Skip to content

Instantly share code, notes, and snippets.

@bronumski
Created May 23, 2016 11:26
Show Gist options
  • Save bronumski/a4acd1baed1591852486cae60087d9ae to your computer and use it in GitHub Desktop.
Save bronumski/a4acd1baed1591852486cae60087d9ae to your computer and use it in GitHub Desktop.
Extension to convert an object to an ExpandoObject
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