Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IDictionary<string, object> ToDictionary(this object data)
- {
- BindingFlags publicAttributes = BindingFlags.Public | BindingFlags.Instance;
- Dictionary<string, object> dictionary = new Dictionary<string, object>();
- foreach (PropertyInfo property in data.GetType().GetProperties(publicAttributes))
- {
- if (property.CanRead)
- dictionary.Add(property.Name, property.GetValue(data, null));
- }
- return dictionary;
- }
Advertisement
Add Comment
Please, Sign In to add comment