[API Proposal]: System.Diagnostics.CodeAnalysis.StringSyntaxAttribute #62505
Closed
Description
opened on Dec 7, 2021
Background and motivation
VS provides nice colorization of regular expressions when passed to known methods on Regex, e.g.
It also supports putting a comment before any string to mark the language being used in that string:
But there's currently no way to define an arbitrary API and annotate a string parameter as to what language is expected, e.g. you don't get this colorization today for RegexGenerator, because VS hasn't been taught about this API specifically:
While these examples are about regex, more generally this applies to arbitrary domain-specific languages. If VS adds colorization for JSON, for example, it'd be nice if every API that accepts JSON could be annotated appropriately.
API Proposal
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class StringLanguageAttribute : Attribute
{
public StringLanguageAttribute(string language);
public string Language { get; }
}
}
API Usage
public sealed class RegexGeneratorAttribute : Attribute
{
public RegexGeneratorAttribute([StringLanguage("regex")] string pattern);
}
Alternative Designs
No response
Risks
No response
Activity