Can attributes be added dynamically in C#?

后端 未结 10 827
别跟我提以往
别跟我提以往 2020-11-22 14:32

Is it possible to add attributes at runtime or to change the value of an attribute at runtime?

10条回答
  •  失恋的感觉
    2020-11-22 15:02

    Attributes are static metadata. Assemblies, modules, types, members, parameters, and return values aren't first-class objects in C# (e.g., the System.Type class is merely a reflected representation of a type). You can get an instance of an attribute for a type and change the properties if they're writable but that won't affect the attribute as it is applied to the type.

提交回复
热议问题