Created
May 23, 2016 11:26
-
-
Save bronumski/a4acd1baed1591852486cae60087d9ae to your computer and use it in GitHub Desktop.
Extension to convert an object to an ExpandoObject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DynamicExtensions | |
{ | |
public static dynamic ToDynamic(this object value) | |
{ | |
IDictionary<string, object> expando = new ExpandoObject(); | |
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType())) | |
expando.Add(property.Name, property.GetValue(value)); | |
return expando as ExpandoObject; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment