Skip to content

feat : Add StringSyntax for regex parameters#40589

Merged
mkArtakMSFT merged 7 commits intodotnet:mainfrom
ShreyasJejurkar:string-syntax
Jan 21, 2023
Merged

feat : Add StringSyntax for regex parameters#40589
mkArtakMSFT merged 7 commits intodotnet:mainfrom
ShreyasJejurkar:string-syntax

Conversation

@ShreyasJejurkar
Copy link
Contributor

@ShreyasJejurkar ShreyasJejurkar commented Mar 8, 2022

No functional changes.
Visual Studio understands this attribute and colorizes the parameter as string holds special meaning.

Tagging @stephentoub here in case if anything to improve about attribute usage! :)

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Mar 8, 2022
@ShreyasJejurkar ShreyasJejurkar marked this pull request as ready for review March 8, 2022 12:02
internal class RuleRegexParser
{
public static ParsedModRewriteInput ParseRuleRegex(string regex)
public static ParsedModRewriteInput ParseRuleRegex([StringSyntax(StringSyntaxAttribute.Regex)] string regex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal class. Does it matter whether this is attributed? It would only affect a developer working on this library and passing in a literal string. No existing call sites take literal strings. I'd revert this and all other similar cases.

Copy link
Contributor Author

@ShreyasJejurkar ShreyasJejurkar Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have reverted this. But shouldn't we consider the internal developer's productivity working on the project? Whether the type is public or not, the string still holds a special meaning (in this case which is regex) and should be annotated so that developer would get a sense of what needs to pass here!
Am totally ok with this approach of excluding internal types, but I think having attributes on internal types is helpful as well! :)

Copy link
Member

@stephentoub stephentoub Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty obvious from the parameter name what this is (and the attribute doesn't show up in intellisense whereas the parameter name does) , and there's zero functional benefit to the attribute if the argument isn't a literal, which it never is here. From my perspective, attributing such things is just noise that actually harms the dev experience.

public RedirectRule([StringSyntax(StringSyntaxAttribute.Regex)] string regex, string replacement, int statusCode)
{
if (string.IsNullOrEmpty(regex))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on it, but as an aside, the | RegexOptions.CultureInvariant below is a nop. CultureInvariant only means something when IgnoreCase is also specified.

@mkArtakMSFT mkArtakMSFT added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 8, 2022
@mkArtakMSFT
Copy link
Contributor

Thanks for your PR, @ShreyasJejurkar.
@javiercn can you please review this? Thanks!

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me on the routing side, although it's not very useful since a user doesn't call this constructor directly.

@stephentoub
Copy link
Member

stephentoub commented Mar 8, 2022

although it's not very useful since a user doesn't call this constructor directly.

If the parameter is never used with literals at the call site, I don't think we should bother using the attribute. At that point it only clutters up the code without actually adding value.

@javiercn javiercn removed their assignment Jan 17, 2023
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good routing wise

@mkArtakMSFT
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@mkArtakMSFT mkArtakMSFT self-assigned this Jan 20, 2023
@mkArtakMSFT mkArtakMSFT merged commit 1078da9 into dotnet:main Jan 21, 2023
@ghost ghost added this to the 8.0-preview1 milestone Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants