When editing a string in Visual Studio there's an option called Enable All JSON editor features
, which adds a comment to the data.
The comment looks like this:
/*lang=json,strict*/
It pops up only if the string in C# code contains serialized JSON. I wasn't able to find any documentation online for it. Is it some hidden feature? Are other languages (SQL/YAML/JavaScript) supported in strings in a similar fashion?
CodePudding user response:
I only know that lang=regex
is also supported.
However, in .NET7 for:
- better handling of string literals and
- adding a semantic meaning to strings
please see:
- Raw string literals:
StringSyntaxAttribute
which allows you to mark parameters with their meaning which then becomes a clue to the editor. For example:
in an editor which supports it (e.g. Visual Studio 2022) would:var s = "..."; ... void F([StringSyntax(StringSyntaxAttribute.DateTimeFormat)]string s)
- add hints as you type
s
(hints withyyyy
,MM
, etc.), - add errors if the string doesn't make sense (in my experience this works best with
StringSyntaxAttribute.Json
for now).
As of Jan 2023 this feature is neither finished nor documented well. The best introduction I know is The .NET 7 feature that gives meaning to your Strings (video, ~7mins).
- add hints as you type