Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DisplayData
- {
- private static DisplayData instance = null;
- private DisplayData() { }
- public static DisplayData Instance
- {
- get
- {
- if (instance == null)
- instance = new DisplayData();
- return instance;
- }
- }
- /// <summary>
- /// Get Attibute alias from Data annotation. If no exist Display(Name=) into attribute,
- /// this method return name of attributes
- /// </summary>
- /// <param name="objClass">class parent</param>
- /// <param name="propertyName"> attribute name</param>
- /// <returns>Alias name</returns>
- public string GetAttributeAlias(object objClass, string propertyName)
- {
- var attrType = typeof(DisplayAttribute);
- var property = objClass.GetType().GetProperty(propertyName);
- if (property.CustomAttributes.Count() > 0)
- return ((DisplayAttribute)property.GetCustomAttributes(attrType, false).First()).Name;
- else
- return property.Name;
- }
- /// <summary>
- /// Get Attibute value.
- /// </summary>
- /// <param name="objClass">class parent</param>
- /// <param name="propertyName"> attribute name</param>
- /// <returns>attribute value</returns>
- public object GetAttributeValue(object objClass, string propertyName)
- {
- var property = objClass.GetType().GetProperty(propertyName);
- return property.GetValue(objClass, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement