Mit dieser Extension method ist es möglich die Beschreibung einer Property (mittels DataAnnotation) z.B. auf der GUI in WPF auszugeben.
/// /// Extends PropertyInfo with a method to show the description of the property in [Description("HERE!")] /// ///The property info /// The description text of the property if available. internal static string GetPropertyDescription(this PropertyInfo propertyInfo) { object[] attribArray = propertyInfo.GetCustomAttributes(false); if (attribArray.Length == 0) { return propertyInfo.ToString(); } else { DescriptionAttribute attrib = attribArray[0] as DescriptionAttribute; return attrib.Description; } }
Beispiel:
var someProperty = typeof(GPN.Configuration).GetProperties().First(); var descriptionOfProperty = someProperty.GetPropertyDescription();
Schreibe einen Kommentar