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)
Before
Section titled “Before”[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.