获取类自定义特性问题,求解?
通过GetCustomAttributes获取类属性的自定义特性失败,所有属性为值类型的全部获取成功,引用类型的属性则获取失败,问题出在哪?其中对B类使用反射获取B类的属性test,a1的自定义特性simpale,属性test的特性获取成本,a1则失败,类如下:Public Class A
<simpale()>
public property test as string
End Class
Public Class B
<simpale()>
public property test as string
<simpale()>
public Overridable Property a1 as A
End Class --------------------编程问答-------------------- Attribute不能被继承。 --------------------编程问答-------------------- 我在声明特性类时已经设定是可以被继承的
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True, Inherited:=True)> --------------------编程问答-------------------- 你是如何获取的?
估计你连PropertyInfo都没有得到,就别提Attribute了。 --------------------编程问答--------------------
For Each item As PropertyInfo In newEntity.GetType.GetProperties
item.GetCustomAttributes(GetType(PropertMap), True).Count = 0
next
PropertMap自定义的特性类
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True, Inherited:=True)> _
Public Class PropertMap
Inherits Attribute
End Class --------------------编程问答-------------------- 上面代码打错了,应该是
For Each item As PropertyInfo In newEntity.GetType.GetProperties
msgbox (item.GetCustomAttributes(GetType(PropertMap), True).Count.ToString )
next
补充:.NET技术 , VB.NET