ObjectHelper.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace wispro.sp.share.Utility
  9. {
  10. public class ObjectHelper
  11. {
  12. public static dynamic GetPropertyValue(string propertyName, object obj)
  13. {
  14. Type type = obj.GetType();
  15. PropertyInfo property = type.GetProperty(propertyName);
  16. dynamic value = property.GetValue(obj);
  17. return value;
  18. }
  19. public static string GetPropertyDescription(string propertyName, string bindObjectType)
  20. {
  21. Type type = Type.GetType(bindObjectType);
  22. PropertyInfo property = type.GetProperty(propertyName);
  23. DescriptionAttribute att =
  24. property.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
  25. if (att == null)
  26. {
  27. return propertyName.ToString();
  28. }
  29. else
  30. {
  31. return att.Description;
  32. }
  33. }
  34. }
  35. }