public static dynamic AnonymousTypeToExpando(object obj)
{
IDictionary<string, object> expando = new ExpandoObject();
if (obj != null)
{
var allProperties = obj.GetType().GetProperties().Select((p) => new { p.Name, Value = p.GetValue(obj, null) });
foreach (var property in allProperties.Where(p => !expando.ContainsKey(p.Name)))
expando.Add(property.Name, property.Value);
}
return expando;
}