Make dapper SQL be syntax colorized

c# colorize dapper visual-studio

Question

If one were bound and determined to get Dapper SQL strings in a C# project syntax colorized in Visual Studio (and for a bonus, syntax checked or even intellisense-capable!), how would one go about it?

Some wild ideas I had:

  • Create a new language that is in reality C#, but has just enough differences to support inline SQL somehow (not inside double quotes).
  • Make a Visual Studio plugin (or modify the attendant VS code some way) that at some point manages to get code colorization in.

Who knows what other options there might be.

I get that achieving my objective could be very costly in terms of effort, time, resources, etc. I'm asking from the perspective of, if you had those resources, what would it actually take?

Accepted Answer

There is already a Visual Studio Add In for doing this. Check it out!

From their site:

This Visual Studio 2010 extension adds basic SQL syntax highlighting (keywords, functions and variables) to string literals.

In addition, you can get the source code and customize it anyway you feel fit to (including adding specific Dapper keywords).


Popular Answer

Writing a Visual Studio plugin to do this isn't quite so hard, you can do it all in C#. Here's a sample I used as a reference when doing this once before. I would recommend leaving out the completion bits at first, it makes things easier to work with.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why