Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- namespace System
- {
- public static class TypeExtentions
- {
- public static string[] GetPropertyNames(this object obj)
- {
- return GetPropertyNames(obj.GetType());
- }
- public static string[] GetPropertyNames(this Type t)
- {
- return TypeDescriptor.GetProperties(t)
- .OfType<PropertyDescriptor>()
- .Select(p => p.Name)
- .ToArray();
- }
- public static Dictionary<string, object> GetPropertyValues(this object obj)
- {
- var dictionary = TypeDescriptor.GetProperties(obj)
- .OfType<PropertyDescriptor>()
- .ToDictionary(p => p.Name, p => p.GetValue(obj));
- return dictionary;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment