【发布时间】:2012-07-30 14:26:06
【问题描述】:
我有一个 3 属性的类。
class Issuance
{
[MyAttr]
virtual public long Code1 { get; set; }
[MyAttr]
virtual public long Code2 { get; set; }
virtual public long Code3 { get; set; }
}
我需要通过我的自定义属性([MyAttr])选择这个类中的一些属性。
我使用 GetProperties() 但这会返回所有属性。
var myList = new Issuance().GetType().GetProperties();
//Count of result is 3 (Code1,Code2,Code3) But count of expected is 2(Code1,Code2)
我该怎么做?
【问题讨论】:
-
您需要对每个属性使用 GetCustomAttributes 并检查返回的任何属性是否属于 MyAttr 类型。
标签: c# reflection attributes custom-attributes