How to highlight dynamic code in visual studio
T

1

19

Is it possible and if so how, to make Visual Studio highlight dynamic expressions in code?

When I just hovered above some code, visual studio told me it was a dynamic expression. This made me realize I made a mistake in my code and used one dynamic too many. But I also realized that if I had not hovered, a 'huge swath' of dynamic code that was supposed to be static would have escaped.

So I wondered if it is possible to make Visual Studio change the background color of dynamic expressions, so those pieces will be clearly recognizable.

[edit]
With dynamic expressions I mean the use of the dynamic keyword in regular code.

Topping answered 8/3, 2011 at 9:48 Comment(6)
+1 Great question... it's what scares me away from the DLR.Monocular
Sorry, I'm clueless - what do you mean dynamic code here? Operations on a dynamic variable? The System.CodeDom classes? Something else?Malvin
@Rup, with dynamic code I mean the use of the dynamic keyword. Edited the question a bit to clarify. Thanks for pointing it out.Topping
Have you visited the Visual Studio Gallery to check the avaliable extensions?Gales
@Morvader, I didn't even know such site existed. I'll check it out.Topping
Have you tried Visual Assist by wholetomato.com? Not sure if it provides the feature you are looking for.Nine
T
8

You would need an Extension. You can create your own, but I would suggest getting pre-built ones.

Visual Studio has a lot of extensions lately, because of it's popularity. There are many options I could suggest, but many are rather buggy, so I would suggest using one of the safer, more well known ones like Resharper (my all time favorite and that of many others as well)

I also like JustCode.

There are so many others available though, and if you want to find them, cruise down the Visual Studio Gallery like Morvader said. Visual Studio Gallery

EDIT:
2 notes I forgot to mention:

  • Dynamic Intellisense is included in Resharper
  • Dynamic Highlighting is included as well. If you want to modify the color from the default light blue you can go to Tools->Options...->Environments->Fonts and Colors->Display items->ReSharper Late Bound Identifier
    Also make sure that in Resharper->Options...->Code Inspection->Settings "Enable code analysis" and "Color identifiers" are checked.
Tuyere answered 13/3, 2011 at 20:51 Comment(3)
Thanks - can you recommend a pre-built extension that will highlight dynamic variables? (or can be configured to?)Malvin
@Malvin Resharper has it prebuilt. Edited the answer to clarify that. @Patrick Huizinga , tell me if this solves your problem buddy.Tuyere
Sorry for the late reply. I found the color option you mentioned. At first ran into the issue that I did not have Resharper coloring enabled. I edited your answer about the specific option and about enabling coloring. (now if only someone could approve it)Topping

© 2022 - 2024 — McMap. All rights reserved.