I have a Helper method like this to get me the PropertyName (trying to avoid magic strings)
public static string GetPropertyName<T>(Expression<Func<T>> expression)
{
var body = (MemberExpression) expression.Body;
return body.Member.Name;
}
However sometimes my PropertyNames aren't named well either. So I would like to rather use the DisplayAttribute.
[Display(Name = "Last Name")]
public string Lastname {get; set;}
Please be aware I am using Silverlight 4.0. I couldnt find the usual namespace DisplayAttributeName attribute for this.
How can I change my method to read the attribute (if available) of th eproperty instead?
Many Thanks,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…