How to extract the type parameters from an attribute (not the aspect)?

If I'm seeking to extract the generic types applied to a class I've marked with an attribute, this is easily done with:
var genericType = builder.Target.TypeParameters[0];
var genericType = builder.Target.TypeParameters[0];
However, when looking at the attributes applied to the target, I don't see that there's a TypeParameters property on the IAttribute:
var myAttribute = builder.Target.Attributes.First(a => a.Type is {} namedType && namedType.TypeDefinition.Is(typeof(MyAttribute<>)));
var myAttribute = builder.Target.Attributes.First(a => a.Type is {} namedType && namedType.TypeDefinition.Is(typeof(MyAttribute<>)));
How do I access the generic type parameters of the attribute applied to the type I'm decorating with a Metalama aspect? Thank you!
1 Reply
Petr Onderka
Petr Onderka2y ago
You can get the type arguments using namedType.TypeArguments.
Want results from more Discord servers?
Add your server