动态地添加属性的ExpandoObject [英] Dynamically adding properties to an ExpandoObject
本文介绍了动态地添加属性的ExpandoObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在运行时动态性能到ExpandoObject补充。因此,例如,添加一个字符串属性调用NewProp我想写点东西像
变种x =新ExpandoObject();
x.AddProperty(NewProp,System.String);
这是容易做到?
解决方案
动态X =新ExpandoObject();
x.NewProp =的String.Empty;
或者
变种x =新ExpandoObject()作为IDictionary的<字符串对象&gt ;;
x.Add(NewProp的String.Empty);
I would like to dynamically add properties to a ExpandoObject at runtime. So for example to add a string property call NewProp I would like to write something like
var x = new ExpandoObject();
x.AddProperty("NewProp", System.String);
Is this easily possible?
解决方案
dynamic x = new ExpandoObject();
x.NewProp = string.Empty;
Alternatively:
var x = new ExpandoObject() as IDictionary<string, Object>;
x.Add("NewProp", string.Empty);
这篇关于动态地添加属性的ExpandoObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文