Good day!
I\'ve such method to get [DisplayName] attribute value of a property (which is attached directly or using [MetadataType] attribut
I found another nice code snippet here, and I have slightly modified it for 'DisplayName' purpose
public static string GetDisplayName(Expression> expression)
{
var attribute = Attribute.GetCustomAttribute(((MemberExpression)expression.Body).Member, typeof(DisplayNameAttribute)) as DisplayNameAttribute;
if (attribute == null)
{
throw new ArgumentException($"Expression '{expression}' doesn't have DisplayAttribute");
}
return attribute.DisplayName;
}
And usages
GetDisplayName(i => i.PropertyName)