Skip to content

[C# Generator] Custom code (CustomCodeView) properties missing attributes from Roslyn parser #10321

@live1206

Description

@live1206

Bug Description

The C# generator's custom code (CustomCodeView) Roslyn parser does not extract attributes from properties defined in custom .cs files. When PropertyHelpers.GetAllProperties() returns properties from CustomCodeView, their Attributes collection is always empty — even if the custom code declares attributes like [Obsolete], [EditorBrowsable], etc.

This prevents the generator from detecting attributes on custom code properties at generation time.

Impact

The Azure SDK mgmt generator (@azure-typespec/http-client-csharp-mgmt) added logic in PR Azure/azure-sdk-for-net#57986 to skip [Obsolete] properties during @@Legacy.flattenProperty processing. However, this check (IsObsoleteProperty) always returns false for custom code properties because attributes are not populated.

Steps to Reproduce

  1. Define a TypeSpec model with a property (e.g., startTimeUtc)
  2. In custom code (partial class), declare the same property with [Obsolete]
  3. At generation time, access modelProvider.CustomCodeView.Properties and check property.Attributes

Expected: Attributes contains the [Obsolete] attribute
Actual: Attributes is empty (attrCount=0)

Debug Evidence

From the Azure.ResourceManager.Hci SDK generation with debug logging in FlattenPropertyVisitor:

CustomCodeView props: [StartTimeUtc(obsolete=False, attrCount=0, attrTypes=[]),
                       EndTimeUtc(obsolete=False, attrCount=0, attrTypes=[]),
                       LastUpdatedTimeUtc(obsolete=False, attrCount=0, attrTypes=[])]

The custom .cs file declares:

[Obsolete("This property is now deprecated.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public DateTimeOffset? StartTimeUtc { get => throw new NotSupportedException(); ... }

Expected Fix

The Roslyn parser that builds PropertyProvider instances from custom code should also extract AttributeData from IPropertySymbol and populate the Attributes collection on the resulting PropertyProvider.

Metadata

Metadata

Labels

bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions