public static string PropertyAbbreviation(this object obj, string propName) { if (obj == null) { Compute.RecordError("Cannot query the property abbreviation of a null object."); return(""); } if (propName == null) { Compute.RecordError("Cannot query the property abbreviation where the property name is null."); return(""); } System.Reflection.PropertyInfo prop = obj.GetType().GetProperty(propName); if (prop != null) { object[] attributes = prop.GetCustomAttributes(typeof(AbbreviationAttribute), false); if (attributes.Length == 1) { AbbreviationAttribute attribute = (AbbreviationAttribute)attributes[0]; if (attribute != null) { return(attribute.Name); } } } return(""); }
public static string PropertyAbbreviation(this object obj, string propName) { System.Reflection.PropertyInfo prop = obj.GetType().GetProperty(propName); if (prop != null) { object[] attributes = prop.GetCustomAttributes(typeof(AbbreviationAttribute), false); if (attributes.Length == 1) { AbbreviationAttribute attribute = (AbbreviationAttribute)attributes[0]; if (attribute != null) { return(attribute.Name); } } } return(""); }