Reputation: 6585
I set to member of class attibute DataMember.
[DataMember]
internal protected string _FirstName="";
[DataMember]
public string FirstName { get { return _FirstName; }
internal protected set { _FirstName=(value!=null?value:""); } }
Next I want to search class members which have this attribute. But when I type:
Type.GetType("classType").GetProperty("FirstName").Attributes
I get null.
Any idea why this attribute was not found by reflection ?
Upvotes: 0
Views: 1301
Reputation: 185663
You need to call GetCustomAttributes
, not use the Attributes
property.
var attributes = Type.GetType("ClassType").GetProperty("FirstName")
.GetCustomAttributes(typeof(DataMemberAttribute), true);
Upvotes: 3