ObjectExt.cs 624 B

1234567891011121314151617181920212223
  1. using System.Collections.Generic;
  2. namespace Quadarax.Foundation.Core.Object.Extensions
  3. {
  4. public static class ObjectExt
  5. {
  6. public static IDictionary<string, object> GetAllPropertyValues(this object obj)
  7. {
  8. var props = new Dictionary<string, object>();
  9. if (obj == null)
  10. return props;
  11. var type = obj.GetType();
  12. foreach (var prop in type.GetProperties())
  13. {
  14. var val = prop.GetValue(obj, new object[] { });
  15. props.Add(prop.Name, val);
  16. }
  17. return props;
  18. }
  19. }
  20. }