Created
January 14, 2021 01:41
-
-
Save dylanbeattie/94ef563e656ba8c5e133d511cfb95c85 to your computer and use it in GitHub Desktop.
ObjectExtensions.ToDynamic
This file contains 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 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