Getting Your IDE To Recognize Domain Specific Languages
[Rider, Visual Studio, Visual Studio Code]
Suppose you had a program with the following code:
var json =
"""
"name":"james bond",
"retired":true,
"age":45
""";
Console.WriteLine(json);
It looks like this on Visual Studio
And like this on Visual Studio Code
And like this on Rider
Very straightforward.
Did you know it is possible to tell your IDE that the string is json
?
Do that by adding the following comment just before the string
//lang=sql
var json =
"""
"name":"james bond",
"retired":true,
"age":45
""";
It will look like this in Visual Studio, with a squiggly indicator. Notice also the syntax highlighting
If you hover your mouse over that you see the following:
It is basically saying that the json
is invalid (no opening and closing curly braces!)
The same thing for Visual Studio Code
And if you hover your mouse …
This also works with Rider
If you mouse over …
This also works for a few other domain specific languages:
- Regular Expressions
- SQL
- XML
- Javascript
- CSS
- HTML
Happy hacking!