#动态属性ExpandoObject

动态对象 ExpandoObject中添加动态属性?

1
2
3
4
5
6
7
8
dynamic obj = new ExpandoObject();
IDictionary<string, object> temp = new Dictionary<string, object>();
temp.Add(Key, Value);

foreach (KeyValuePair<string, object> item in temp)
{
((IDictionary<string, object>)obj).Add(item.Key, item.Value);
}

因为不难发现ExpandObject继承自以下接口:
IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable