SRReflection.cs 546 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Reflection;
  3. namespace SRF.Helpers
  4. {
  5. public static class SRReflection
  6. {
  7. public static void SetPropertyValue(object obj, PropertyInfo p, object value)
  8. {
  9. p.GetSetMethod().Invoke(obj, new object[]
  10. {
  11. value
  12. });
  13. }
  14. public static object GetPropertyValue(object obj, PropertyInfo p)
  15. {
  16. return p.GetGetMethod().Invoke(obj, null);
  17. }
  18. public static T GetAttribute<T>(MemberInfo t) where T : Attribute
  19. {
  20. return Attribute.GetCustomAttribute(t, typeof(T)) as T;
  21. }
  22. }
  23. }