[C# Generator] Populate attributes from custom code properties and fields in NamedTypeSymbolProvider#10322
Open
[C# Generator] Populate attributes from custom code properties and fields in NamedTypeSymbolProvider#10322
Conversation
…der.BuildProperties Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/24b2dbde-3903-4684-830e-2b03e1d84dd2 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing attributes for CustomCodeView properties
[C# Generator] Populate attributes from custom code properties in NamedTypeSymbolProvider
Apr 9, 2026
...lient-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs
Outdated
Show resolved
Hide resolved
...erator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs
Show resolved
Hide resolved
…pe.Equals, argument validation, and custom attribute Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1c0103ad-e7d0-4e76-b18f-12805d30824b Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Copilot
AI
changed the title
[C# Generator] Populate attributes from custom code properties in NamedTypeSymbolProvider
[C# Generator] Populate attributes from custom code properties and fields in NamedTypeSymbolProvider
Apr 9, 2026
...erator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs
Show resolved
Hide resolved
...lient-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/NamedTypeSymbolProvider.cs
Outdated
Show resolved
Hide resolved
commit: |
…, update expected output Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/96747ddb-cde5-4ed0-a8b9-27a2beaca6d3 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
...ializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizePropertyUsingField.cs
Outdated
Show resolved
Hide resolved
…tes to constructor parameters Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/2aa57a53-e9f5-4f62-b4a3-eafbe19db041 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
… to constructor parameters Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/52c392ca-eff3-412f-ad7b-8142cb7871b1 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
… FieldProvider Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c117587e-318d-4500-a614-6f4388418265 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
JoshLove-msft
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NamedTypeSymbolProvider.BuildProperties()andBuildFields()never passed symbol attributes to thePropertyProvider/FieldProviderconstructors, soCustomCodeView.Properties[*].AttributesandCustomCodeView.Fields[*].Attributeswere always empty. This blocked downstream consumers (e.g., mgmt generator) from detecting attributes like[Obsolete]on custom code properties and fields.Changes
NamedTypeSymbolProvider.cs: ExtractAttributeDatafrom eachIPropertySymbolandIFieldSymboland pass asattributes:parameter when constructingPropertyProviderandFieldProvider. All attributes (including internal CodeGen attributes) are passed through without filtering. Uses.ToArray()because the constructor's(attributes as IReadOnlyList<AttributeStatement>) ?? []silently drops unmaterializedIEnumerable.FieldProvider.cs: UpdatedInitializeParameter()to filter out codegen-related attributes (from theMicrosoft.TypeSpec.Generator.Customizationsnamespace) when propagating field attributes to constructor parameters viaAsParameter. This ensures user-facing attributes like[Obsolete]propagate to generated constructor parameters, while internal codegen attributes like[CodeGenMember]do not appear in generated code. The field itself retains all attributes for downstream consumers.CanReadPropertyAttributeswith a custom code file declaring[Obsolete](with a named argumentDiagnosticId),[EditorBrowsable], and a custom non-system attribute on a property, plus[Obsolete]on a field. The test validates attribute types usingCSharpType.Equals, checks argument counts, validatesPositionalArguments, and ensures the generator does not throw for custom non-system attributes.