问题描述
我正在寻找一种方式来从动态对象动态删除成员(可能是我们可以使用Expando的对象吗?)。
I'm looking for a way to remove members dynamically from an dynamic object (may be can we use Expando object here?).
OK,我想是需要一点澄清...
OK, I guess a little clarification is needed...
当你做到这一点:
dynamic foo = new ExpandoObject();
foo.Bar = 42;
foo.Jar = 25;
的
酒吧
,'罐子'属性将在运行时动态添加。我显示该用户,他还可以加入自己的属性(表格可选项),这可以通过仅仅增加成员动态对象来完成。
The Bar
, 'jar' property will be added dynamically at runtime. I am displaying this to user , he may further add his own properties (form available option), this can be done by just adding member to dynamic object.
但他也可以删除成员(说'罐')形成Foo对象,我们怎么删除成员形成动态对象?可我们这里使用了Expando对象?
But he can also remove members (say 'Jar') form the Foo object, how do we remove the member form dynamic object? Can we use Expando object here?
推荐答案
可以治疗的作为的代替,然后将其删除这种方式:
You can treat the ExpandoObject
as an IDictionary<string, object>
instead, and then remove it that way:
IDictionary<string, object> map = foo;
map.Remove("Jar");
这篇关于动态地去除为Expando /动态对象的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!