Can I define C# aliases/keywords for my own classes like int, string, object?
alias, c#, types, visual-studio
Solution
Your question seems to be about two distinct requirements:
- Define a "global" symbol/class, available everywhere.
- Apply a distinct color (i.e. syntax highlighting) for that symbol.
1) Not directly possible. What you could do in this case is providing an assembly containing that class, and enforce its usage by your team. You could even use a static analysis tool and trigger some compile errors (say, if that assembly is not referenced).
2) This is even harder to implement. Customizing the default syntax colorization mechanism for C# in Visual Studio is possible, but definitely not easy.
Visual studio supports a given language (with syntax highlighting, IntelliSense and so forth) through a Language Service. So it could be feasible to add a custom set of keywords, with a distinct color palette, by following these steps. You would also have to find out how to to plug your custom code into the already defined C# Language Service.
PS: Never tried doing that, and I get tired just looking at the work that seems to be needed. But I guess that's what the JetBrains ReSharper team did.
PPS: If you were using Managed C++ instead of C# it would be much simpler.
Problem
Its not about `using foo = MyPackage.Foo;` I realize this has more to do with the IDE (Visual Studio 2010) that shows me special types in blue. And I want the same for some of my classes. I want it blue (presented as special) and be accessible in the whole project. The reason is that I want to give them meaning/importance so that everyone in my team knows this class is a key class of the whole project. ``` // "foo" and "Foo" shall be just the same type: foo: MyPackage.Foo object: System.Object string: System.String bool: System.Boolean byte: System.Byte sbyte: System.SByte short: System.Int16 ushort: System.UInt16 int: System.Int32 uint: System.UInt32 long: System.Int64 ulong: System.UInt64 float: System.Single double: System.Double decimal: System.Decimal char: System.Char ``` Is that possible ? If there would be a file in the installation of my IDE and there would be the above keywords inside and I could add some keywords to it and save it and restart the IDE ? To have 2 classes do the very same I could do this. It would be 2 names for the same class. I know I would need to cast between those. ``` public class foo : Foo { } ```