Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
StringSyntaxAttribute is placed on strings to tell tooling what format the string will take. For example, regex, JSON, XML, date format string, etc. This is then used to provide helpful features such as completion of date format strings, regex/JSON/XML highlighting, analyzers, etc.
We should ensure all the ASP.NET Core strings have this attribute where appropriate, so ASP.NET Core APIs get tooling enhancements.
Describe the solution you'd like
Audit dotnet/aspnetcore source and add StringSyntax attribute with format strings as needed:
- CompositeFormat - The syntax identifier for strings containing composite formats for string formatting.DateOnlyFormat - The syntax identifier for strings containing date format specifiers.DateTimeFormat - The syntax identifier for strings containing date and time format specifiers.EnumFormat - The syntax identifier for strings containing enum format specifiers.GuidFormat - The syntax identifier for strings containing GUID format specifiers.Json - The syntax identifier for strings containing JavaScript Object Notation (JSON).NumericFormat - The syntax identifier for strings containing numeric format specifiers.Regex - The syntax identifier for strings containing regular expressions. feat : Add
StringSyntax
for regex parameters #40589TimeOnlyFormat - The syntax identifier for strings containing time format specifiers.TimeSpanFormat - The syntax identifier for strings containing TimeSpan format specifiers.Uri - The syntax identifier for strings containing URIs.Xml - The syntax identifier for strings containing XML.
I expect many of these won't have any usage - e.g. the format strings (except CompositeFormat) - but we should have Regex, Uri, Json and Xml.
Additional context
No response
Metadata
Metadata
Assignees
Labels
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesGood for newcomers.Indicates that the issues may be a good fit for community to help with. Requires work from eng. teamUp for grabs. We would accept a PR to help resolve this issue
Activity
danmoseley commentedon Oct 14, 2022
Example of this kind of thing done previously in runtime
dotnet/runtime#67621
blouflashdb commentedon Oct 14, 2022
I would love to help here.
danmoseley commentedon Oct 14, 2022
I have assigned to you @blouflashdb
blouflashdb commentedon Oct 14, 2022
#44555 PR for CompositeFormat
more will follow soon.
blouflashdb commentedon Oct 15, 2022
@JamesNK I have a question about StringSyntaxAttribute.Uri.
There are some places where a RelativeIUri is passed as an parameter. I saw that optinal arguments can be added to StringSyntaxAttribute for example uriKind. How should the StringSyntaxAttribute look like for relative uri?
There is also one place in the code where a relative or absolute url can be passed to the methode. For Example WebViewManager.Navigate . How to handle this case?
JamesNK commentedon Oct 15, 2022
Good question. Thanks for thinking about this.
I think
StringSyntaxAttribute.Uri
should be used for both relative and absolute URLs. ForUriKind
, an example of it is on theUri
ctor, and it looks like it the parameter named is passed as an argument on the attribute - https://github.com/dotnet/runtime/blob/9bcbf50d9ebe60cd83ed724179a5a503cbf03702/src/libraries/System.Private.Uri/src/System/Uri.cs#L405-L414@stephentoub I see you added Uri throughout dotnet/runtime in dotnet/runtime#67621. Any extra input on these StringSyntaxAttribute usages?
danmoseley commentedon Oct 15, 2022
btw @CyrusNajmabadi just curious what the status of tooling support for these is? Do you expect them to all have an experience like regex has?
blouflashdb commentedon Oct 15, 2022
Does StringSyntaxAttribute also works on parameters like this? params string[] urls ?
JamesNK commentedon Oct 15, 2022
I tested it, and yes it does:
However, looks like there is a bug in Roslyn where it only applies it to the first string. New Roslyn issue: dotnet/roslyn#64756
CyrusNajmabadi commentedon Oct 15, 2022
We can add support if the language provides a suitable parser we can depend on.
46 remaining items