Skip to content

[API Proposal] Add StringSyntaxAttributes to SqlJson #3107

@edwardneal

Description

@edwardneal

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.

Metadata

Metadata

Assignees

Labels

Enhancement 💡Issues that are feature requests for the drivers we maintain.P3Use for tagging low priority issues, impacts a single customer, and is not a critical/high issue.Public API 🆕Issues/PRs that introduce new APIs to the driver.Triage Done ✔️Issues that are triaged by dev team and are in investigation.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions