我想在运行时动态地将属性添加到ExpandoObject。因此,例如添加一个字符串属性调用NewProp,我想写一些类似的东西
var x = new ExpandoObject(); x.AddProperty("NewProp", System.String);
这容易吗?
dynamic x = new ExpandoObject(); x.NewProp = string.Empty;
或者:
var x = new ExpandoObject() as IDictionary<string, Object>; x.Add("NewProp", string.Empty);