动态添加属性到动态对象? [英] Dynamically adding properties to a dynamic object?
本文介绍了动态添加属性到动态对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个
dynamic d = new ExpandoObject();
d.Name = attribute.QualifiedName.Name;
所以,我知道d将有一个属性名称。现在如果我不知道属性在编译时的名称,我如何添加该属性的动态。
i找到此问题
so , i know that d will have a property Name. Now if i don't know the name of the property at compile time , how do i add that property to the dynamic. i found this SO Question
所以,有一个复杂的调用绑定等概念。这是很难得到的第一个地方。任何更简单的方法这样做?
so, there is this complicated concept of call binders etc..which is tough to get in the first place.any simpler way of doing this ?
推荐答案
dynamic d = new ExpandoObject();
((IDictionary<string,object>)d)["test"] = 1;
//now you have d.test = 1
这篇关于动态添加属性到动态对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文