【发布时间】:2013-05-24 15:51:37
【问题描述】:
假设我有:
[Description("Class Description")]
public class A { }
public class B {
public A PropertyA { get;set;}
}
当我反思PropertyA时,我看到了A类的属性。为什么?
var entityProperties = TypeDescriptor.GetProperties(typeof(B)).Cast<PropertyDescriptor>();
foreach (var a in entityProperties.First().Attributes)
Console.Out.Write(a.GetType().ToString());
打印出来:
System.ComponentModel.DescriptionAttribute
为什么当我反映属性时,DescriptionAttribute 在列表中?如何排除类属性并仅获取附加到属性的属性?
【问题讨论】:
标签: c# .net reflection custom-attributes