19

Is it possible to color instance (and static) variables in C# code in Visual Studio 2010, perhaps using a lightweight extension?

In following example name and age should be colored but test not. Of course, usages of variable highlighting is grat feature but this is something different. I want instance variables to be colored all and always. Many people use _underscores to distinguish instance variables but I prefer to use coloring.

public class Kid 
{
    private string name;
    private int age;

    public Kid() 
    {
        name = "N/A";
        string test = "XYZ";
    }
}
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Pol
  • 5,064
  • 4
  • 32
  • 51
  • 12
    It blows my mind that this has never been implemented in Visual Studio. It is such a basic feature. – Godsmith Dec 29 '14 at 09:28
  • Note that this has been implemented in [Visual Studio 2019](https://devblogs.microsoft.com/dotnet/visual-studio-2019-net-productivity-2/), scroll to "User Members". – jrh Sep 13 '19 at 12:36

3 Answers3

21

SemanticColorizer is working for me in Visual Studio 2015, it is also available through Extensions and Updates in VS. You can edit colors in Options -> Environment -> Fonts and Colors -> Text Editor -> "Semantic *****". Most important extension is only used for code coloring, it is not some suite with thousands of features which will clog your VS. enter image description here

watbywbarif
  • 6,487
  • 8
  • 50
  • 64
  • 3
    This also works with 2017 now. Here is the link to [Semantic Syntax Colorizer at VS Marketplace](https://marketplace.visualstudio.com/items?itemName=AndreasReischuck.SemanticColorizer) – Teknikaali May 02 '17 at 16:03
4

This is not possible directly with Visual Studio. However, if you install Resharper, you will get this option (as well as many other coloration options).

Lord Drake
  • 172
  • 2
  • 12
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • I suppose Resharper has native support for coloring. It adds some rich color options to standard VS "Fonts and Colors" dialog, i.e. you can choose from the list of code elements what style you want this code element to be. I mean Resharpe doesn't change standard dialog, but adds a lot of code elements to list of predefined code elements. – Dmitrii Lobanov Apr 07 '11 at 01:22
  • Since I have JustCode falls to install it and check it out again :-) – Pol Apr 07 '11 at 01:23
  • @Dmitry: JustCode does the same thing, btw - different options, of course, but similar concept. – Reed Copsey Apr 07 '11 at 01:29
  • Oh, my fault, sorry, I've read your message as "JustCode FOR Resharper", I thought you were talking about some colourisation plug-in for Resharper. It's 6 a.m., I've just woken up :) – Dmitrii Lobanov Apr 07 '11 at 02:51
  • Thanks. I checked and JustCode has this feature. What is missing is different color for properties (Foo) vs. instance variables (foo). But still very helpful. – Pol Apr 07 '11 at 22:50
  • Both of those cost money though. – Godsmith Dec 29 '14 at 09:29
  • 2
    Don't know if it has all options as this complex suits, but SemanticColorizer, answer below, is something lightweight that works in VS 2015. – watbywbarif Sep 14 '15 at 08:22
1

This will soon be possible, though not for Visual Studio 2010 in particular. There is an open source Visual Studio extension called Roslyn Colorizer which makes use of the new .NET Compiler Platform ("Roslyn") in Visual Studio 2015 Preview to style the appearance of instance variables.

enter image description here

Mr. Smith
  • 4,288
  • 7
  • 40
  • 82
  • There is an extension for Visual Studio 2013 to implement this, but according to the comments it is not working? https://visualstudiogallery.msdn.microsoft.com/5b1a493f-740e-4428-9fe9-65b0028380f3?SRC=VSIDE – Godsmith Dec 29 '14 at 09:28