Reputation: 9085
Take a look at the following code:
public class MyClass<T>
{
...
}
Working with Java or C++ in eclipse, the T
would be highlighted, as it is a generic template.
How can I achieve this functionality in Visual Studio?
Upvotes: 14
Views: 2179
Reputation: 1078
As @Michael Sander mentioned, User Types would provide this functionality, but only in an inconvenient and partial manner. Assuming this functionality is working for you, here is how you would color generic types as you wish.
The 'usertypes.dat' file must be created by you as a basic text file, and it must be saved to the same location as the Visual Studio executable. Once created, list each of your desired "Generic Type Names" on individual lines. An example would like like so:
T
TIn
TOut
TEntity
Afterwards, save the file and restart Visual Studio. Then Head over to TOOLS -> Environment -> Fonts and Colors and look for
User Types
User Types (Type parameters)
You can now set that color to the color you desire. It is recommended to set both of them to the same color so it works for return types and such.
=====
As an alternative solution, Resharper, a non-free Visual Studio extension, provides something akin to this functionality.
The extension allows you to color "Type Parameters". If you were hoping to only color Generic Type parameters, you are unfortunately, out of luck. But if you do not mind having all type parameters retain the color you desire, that is possible.
If you own Resharper, you can enable this feature like so:
Head over to TOOLS -> Environment -> Fonts and Colors and look for
ReSharper Type Parameter Identifier
This will change any Type parameters to the color of your choice.
While purchasing this extension solely for this problem is likely not a desirable solution, those who already own it will hopefully find this helpful.
Upvotes: 7
Reputation: 7355
There is a feature request, so I can only guess it is not possible rght now:
Feature Request for Visual Studio
Upvotes: 2
Reputation: 2737
Under Tools/Options/Environment/Fonts and Colors
you actually can find User Types (Type parameters)
, but that is currently bugged.
The Color Theme Editor should be able to do the job.
Upvotes: 2