Skip to content

Instantly share code, notes, and snippets.

@dylanbeattie
Created January 14, 2021 01:41
Show Gist options
  • Save dylanbeattie/94ef563e656ba8c5e133d511cfb95c85 to your computer and use it in GitHub Desktop.
Save dylanbeattie/94ef563e656ba8c5e133d511cfb95c85 to your computer and use it in GitHub Desktop.
ObjectExtensions.ToDynamic
public static class ObjectExtensions {
public static dynamic ToDynamic(this object value) {
IDictionary<string, object> expando = new ExpandoObject();
var properties = TypeDescriptor.GetProperties(value.GetType());
foreach (PropertyDescriptor property in properties) {
expando.Add(property.Name, property.GetValue(value));
}
return (ExpandoObject)expando;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment