Skip to content

Attribute Arguments

Question

What kind of data can be passed into attributes?

Short interview answer

Attribute constructor and named arguments are restricted to metadata-compatible values, including primitive values, strings, Type, enums, and arrays of permitted types.

Detailed answer

Attribute arguments are encoded as metadata rather than arbitrary runtime objects. Positional arguments correspond to constructor parameters; named arguments set public fields or properties. This restriction lets tools inspect attributes without executing arbitrary application code.

Sources