匿名对象工具类
public class AnonymousObject
{
private object obj;
public AnonymousObject(object obj)
{
this.obj = obj;
}
public Dictionary<string, object> ToDictionary()
{
var dict = new Dictionary<string, object>();
System.ComponentModel.PropertyDescriptorCollection pds = System.ComponentModel.TypeDescriptor.GetProperties(this.obj);
foreach (System.ComponentModel.PropertyDescriptor pd in pds)
{
dict.Add(pd.Name, pd.GetValue(this.obj));
}
return dict;
}
}