Skip to content

Rework required attributes#11971

Merged
DustinCampbell merged 7 commits intodotnet:mainfrom
DustinCampbell:required-attributes
Jun 24, 2025
Merged

Rework required attributes#11971
DustinCampbell merged 7 commits intodotnet:mainfrom
DustinCampbell:required-attributes

Conversation

@DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Jun 23, 2025

Important

This affects the Razor SDK. When the compiler flows to the .NET VMR, this commit will be needed: dotnet/dotnet@a10383a.

This change makes a few updates RequiredAttributeDescriptor:

  • Un-nest and rename the RequiredAttributeDescriptor.NameComparisonMode and RequiredAttributeDescriptor.ValueComparisonMode enums to RequiredAttributeNameComparison and RequiredAttributeValueComparison, respectively.
  • Remove the Metadata property. There's only one bit of data that was ever stored in the Metadata property: IsDirectiveAttribute. This has been moved to a property on RequiredAttributeDescriptor itself. Interestingly, the compiler doesn't actually use IsDirectiveAttribute. However, it might sometime, so I've left it.
  • Don't serialize the DisplayName property. This always has exactly the same format for any RequiredAttributeDescriptor.

CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2736049&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/645854
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2736052&view=results

This is a fairly mechanical change to clean up the NameComparisonMode and ValueComparisonMode enums nested in RequiredAttributeDescriptor.

- Un-nest NameComparisonMode from RequiredAttributeDescriptor
- Rename NameComparisonMode to RequiredAttributeNameComparison
- Un-nest ValueComparisonMode from RequiredAttributeDescriptor
- Rename ValueComparisonMode to RequiredAttributeValueComparison
- Rename RequiredAttributeDescriptorBuilder.NameComparisonMode property to NameComparison (matches RequiredAttributeDescriptor.NameComparison)
- Rename RequiredAttributeDescriptorBuilder.ValueComparisonMode property to ValueComparison (matches RequiredAttributeDescriptor.ValueComparison )
- Rename TestRequiredAttributeDescriptorBuilderExtensions.NameComparisonMode extension method to NameComparison
- Rename TestRequiredAttributeDescriptorBuilderExtensions.ValueComparisonMode extension method to ValueComparison
- Enable nullability
- Remove unnecessary argument null checks
- Add optional parameter to Name() extension method taking a RequiredAttributeNameComparison.
- Update callers of Name() to pass optional parameter and remove calls to NameComparison()
- Add optional parameter to Value() extension method taking a RequiredAttributeValueComparison.
- Update callers of Value() to pass optional parameter and remove calls to ValueComparison()
- Store CaseSensitive in flag
- Remove "Common.DirectiveAttribute" from Metadata and store in flag.
The RequiredAttributeDescriptor.DisplayName property can be computed , so we can stop serializing/deserializing the display name.
RequiredAttributeDescriptor no longer needs a Metadata property.
@DustinCampbell DustinCampbell requested review from a team as code owners June 23, 2025 20:08
Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

Love it.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants