Problem
Azure management-plane C# generation needs to introduce management-specific CodeGen attributes, for example CodeGenResourceDataAttribute, that are emitted into generated SDK projects and are also available while the generator compiles custom code.
The base C# generator already has built-in CodeGenTypeAttributeDefinition, CodeGenMemberAttributeDefinition, CodeGenSuppressAttributeDefinition, and CodeGenSerializationAttributeDefinition. These are included in CodeModelGenerator.CustomCodeAttributeProviders, but that provider list is not extensible from derived generators.
Because derived generators cannot add their own custom-code attribute providers, Azure management currently has to use reflection to append a TypeProvider to CustomCodeAttributeProviders. If the provider is a normal TypeProvider, it may also need to avoid source-input view lookup before SourceInputModel is initialized.
Request
Please expose a supported extension point for derived C# generators to contribute custom-code attribute providers, such as one of:
- protected virtual IReadOnlyList BuildCustomCodeAttributeProviders()
- protected void AddCustomCodeAttributeProvider(TypeProvider provider)
- another supported API that lets derived generators add generated attribute definitions used during custom-code compilation
Expected usage
Azure management generator should be able to register a provider like CodeGenResourceDataAttributeDefinition so custom code can write:
`csharp
using Microsoft.TypeSpec.Generator.Customizations;
[CodeGenResourceData(typeof(MyCustomResourceData))]
public partial class FooResource { }
`
without the SDK depending on the generator assembly and without reflection in the derived generator.
Related downstream PR
Azure SDK for .NET PR: Azure/azure-sdk-for-net#59851
Problem
Azure management-plane C# generation needs to introduce management-specific CodeGen attributes, for example CodeGenResourceDataAttribute, that are emitted into generated SDK projects and are also available while the generator compiles custom code.
The base C# generator already has built-in CodeGenTypeAttributeDefinition, CodeGenMemberAttributeDefinition, CodeGenSuppressAttributeDefinition, and CodeGenSerializationAttributeDefinition. These are included in CodeModelGenerator.CustomCodeAttributeProviders, but that provider list is not extensible from derived generators.
Because derived generators cannot add their own custom-code attribute providers, Azure management currently has to use reflection to append a TypeProvider to CustomCodeAttributeProviders. If the provider is a normal TypeProvider, it may also need to avoid source-input view lookup before SourceInputModel is initialized.
Request
Please expose a supported extension point for derived C# generators to contribute custom-code attribute providers, such as one of:
Expected usage
Azure management generator should be able to register a provider like CodeGenResourceDataAttributeDefinition so custom code can write:
`csharp
using Microsoft.TypeSpec.Generator.Customizations;
[CodeGenResourceData(typeof(MyCustomResourceData))]
public partial class FooResource { }
`
without the SDK depending on the generator assembly and without reflection in the derived generator.
Related downstream PR
Azure SDK for .NET PR: Azure/azure-sdk-for-net#59851