如何读取定义类型 class 中的 属性 属性?
How to read property attribute in the defining type class?
假设我有一个 属性 定义如下:
[SomeAttriubte("#1")]
public SomeClass Property1 { get; set; }
[SomeAttribute("#2")]
public SomeClass Property2 { get; set; }
哪个 SomeClass 定义是这样的:
public class SomeClass
{
private void PrivateMethod()
{
//Some action
}
}
有没有办法在定义类型 class 中的 PrivateMethod 中读取 SomeAttribute 参数值??
没有。您使用的属性连接到 属性。为了能够访问它们,SomeClass.PrivateMethod()
需要知道它所使用的属性的 PropertyInfo
。但它不能。更"clear":一个类型不知道"where"它被使用,并且不知道"where"它被使用,它不能访问连接到[=16=的地方的属性] 它被使用(以同样的方式它不能访问它所使用的对象 "where" 的 this
)
假设我有一个 属性 定义如下:
[SomeAttriubte("#1")]
public SomeClass Property1 { get; set; }
[SomeAttribute("#2")]
public SomeClass Property2 { get; set; }
哪个 SomeClass 定义是这样的:
public class SomeClass
{
private void PrivateMethod()
{
//Some action
}
}
有没有办法在定义类型 class 中的 PrivateMethod 中读取 SomeAttribute 参数值??
没有。您使用的属性连接到 属性。为了能够访问它们,SomeClass.PrivateMethod()
需要知道它所使用的属性的 PropertyInfo
。但它不能。更"clear":一个类型不知道"where"它被使用,并且不知道"where"它被使用,它不能访问连接到[=16=的地方的属性] 它被使用(以同样的方式它不能访问它所使用的对象 "where" 的 this
)