Skip to content

C# Feature - Generic attributes

Generic attributes let attribute types declare generic parameters so the compiler can enforce type-safe usage.

C# 11.0 (2022)

[Validator(typeof(CustomerValidator))]
public class Customer { }
[Validator<CustomerValidator>]
public class Customer { }
  • Attribute arguments still follow runtime metadata rules.
  • Use this when a Type parameter existed only to carry a compile-time type choice.