可能是重复问题:
如何获取具有给定属性的属性列表?
我有一个自定义类,像这样
public class ClassWithCustomAttributecs
{
[UseInReporte(Use=true)]
public int F1 { get; set; }
public string F2 { get; set; }
public bool F3 { get; set; }
public string F4 { get; set; }
}
我有一个自定义属性UseInReporte
:
[System.AttributeUsage(System.AttributeTargets.Property ,AllowMultiple = true)]
public class UseInReporte : System.Attribute
{
public bool Use;
public UseInReporte()
{
Use = false;
}
}
我希望获取所有使用了
[UseInReporte(Use=true)]
属性的属性,我该如何使用反射实现呢?谢谢。
[UseInReporte(Use=true)]
。 - Jon B.Any()
代替.Count() >= 1
。 - Oliver