属性可以用C#动态添加?可以用、属性、动态

2023-09-02 10:15:57 作者:为自由义无反顾

是否有可能在运行时添加的属性或在运行时改变属性的值?

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

推荐答案

属性是静态的元数据。组件,模块,类型,成员,参数和返回值是在C#中没有第一类对象(如的System.Type类是一类仅仅是一个反映再presentation)。你可以得到一种类型的属性的一个实例,并改变它的性质,如果它们是可写的,但是,这将不影响属性,因为它是应用到该类型

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.