C# Feature - Generic attributes
Overview
Section titled βOverviewβGeneric attributes let attribute types declare generic parameters so the compiler can enforce type-safe usage.
Introduced In
Section titled βIntroduced InβC# 11.0 (2022)
[Validator(typeof(CustomerValidator))]public class Customer { }[Validator<CustomerValidator>]public class Customer { }Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Attribute arguments still follow runtime metadata rules.
- Use this when a
Typeparameter existed only to carry a compile-time type choice.