获取部件,其属性是从内部属性构造函数应用?属性、是从、部件、函数

2023-09-03 02:38:30 作者:空城孤寂旧回忆

我有一个自定义属性,我自定义的构造函数中的属性我想设置我的属性,以我的属性被应用到属性的类型属性的值,在那里好歹访问该成员的属性从我的属性类的内部应用?

I have a custom attribute, inside the constructor of my custom attribute I want to set the value of a property of my attribute to the type of the property my attribute was applied to, is there someway to access the member that the attribute was applied to from inside my attribute class?

推荐答案

属性不工作的方式,我很害怕。他们仅仅是标志,附着于物体,但无法与它们进行交互。

Attributes don't work that way, I'm afraid. They are merely "markers", attached to objects, but unable to interact with them.

属性本身通常应该是缺乏的行为,只是含元数据对于它们所连接的类型。与属性相关联的任何特性应该是由另一个类看起来为属性的presence和执行任务来提供。

Attributes themselves should usually be devoid of behaviour, simply containing meta-data for the type they are attached to. Any behaviour associated with an attribute should be provided by another class which looks for the presence of the attribute and performs a task.

如果您有兴趣的属性应用于类型,这些信息将可在你反映获得属性的同时,

If you are interested in the type the attribute is applied to, that information will be available at the same time you are reflecting to obtain the attribute.