Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight dynamic code in visual studio

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.

like image 305
Patrick Huizinga Avatar asked Mar 08 '11 09:03

Patrick Huizinga


People also ask

How do you highlight lines of code?

If you want to highlight a whole line of text, move your cursor to the start of the line, hold the Shift key, and then press the Down arrow . You may also use the shortcut key combination Shift + End . If you want to highlight all text (the entire page), press the shortcut key Ctrl + A .

Does Visual Studio have syntax highlighting?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.


1 Answers

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.
like image 50
Reza M. Avatar answered Oct 30 '22 12:10

Reza M.