【发布时间】:2015-06-09 20:33:51
【问题描述】:
我正在尝试找到一种方法来访问已从对象内的属性级别应用的属性,但我遇到了障碍。数据似乎存储在类型级别,但我需要它在属性级别。
这是我正在尝试制作的示例:
public class MyClass
{
[MyAttribute("This is the first")]
MyField First;
[MyAttribute("This is the second")]
MyField Second;
}
public class MyField
{
public string GetAttributeValue()
{
// Note that I do *not* know what property I'm in, but this
// should return 'this is the first' or 'this is the second',
// Depending on the instance of Myfield that we're in.
return this.MyCustomAttribute.value;
}
}
【问题讨论】:
-
Is this 你在找什么?
标签: c# attributes