Last active
November 16, 2017 11:52
-
-
Save sebnilsson/5221347 to your computer and use it in GitHub Desktop.
Convert anonymous type to dynamic
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 ExpandoObject ToExpandoObject(this object obj) | |
{ | |
if (obj == null) | |
throw new ArgumentNullException(nameof(obj)); | |
IDictionary<string, object> expando = new ExpandoObject(); | |
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(obj.GetType())) | |
expando.Add(property.Name, property.GetValue(obj)); | |
return (ExpandoObject) expando; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment