-
Notifications
You must be signed in to change notification settings - Fork 314
Description
Is your feature request related to a problem? Please describe.
.NET 7.0 introduced the StringSyntaxAttribute type, which allows fields, parameters and properties of type string
to be marked as containing a specific kind of data. When a member has this attribute applied, data validation rules can be run by Roslyn and Visual Studio to perform static code analysis.
This hasn't yet been threaded through to the new SqlJson type.
Describe the solution you'd like
I'm proposing the API surface change below:
public class SqlJson : INullable
{
- public SqlJson(string? jsonString) { }
+ public SqlJson([StringSyntax(StringSyntaxAttribute.Json)] string? jsonString) { }
+ [StringSyntax(StringSyntaxAttribute.Json)]
public string Value { get { } }
}
After this change, a developer who instantiates a SqlJson instance with a hardcoded string will encounter a new warning in Visual Studio and Rider if that string isn't valid JSON: JSON001. These strings will also have their syntax highlighted.
The StringSyntaxAttribute class isn't available in .NET Framework, but the functionality will still work if an internal type with the same name and definition is part of the assembly. NUnit and part of the dotnet arcade repo do this.
Describe alternatives you've considered
This could be made .NET-only if we'd prefer not to duplicate the type definition.
Additional context
I skimmed the ref projects for SqlClient and didn't see any other places where we can add these attributes.