可以通过索引访问Expandoobject属性吗? [英] Is it possible to access Expandoobject properties by index?
问题描述
可以覆盖动态对象的TryGetIndex方法,以通过索引访问动态对象属性,但是我正在处理一个Expandoobject System.dynamic namespace )你不能继承。有没有解决的办法?谢谢
It is possible to override the TryGetIndex method of a dynamic object to access the dynamic object properties by index however I am dealing with an Expandoobject (of the System.dynamic namespace) which you can't inherit from. Is there a way around this? Thanks
推荐答案
ExpandoObject
只不过是一个花哨的 IDictionary
利用DLR。
ExpandoObject
is nothing but a fancy IDictionary
which leverages the DLR.
没有办法可以访问 IDictionary&TK; TValue& / code>通过索引。你可能会发现linq的
ElementAt
方法很有用,但不是。字典中没有排序,您可以阅读有关哈希表数据结构的更多信息(字典也是哈希表)。
There is no way you can access a IDictionary<TKey,TValue>
via index. You may find ElementAt
method of linq useful, but it is not. There is no ordering in dictionary, You can read more about hashtable datastructure(Dictionary is also a hashtable).
要通过索引访问字典,您可以使用 OrderedDictionary
。一个缺点是这不是一般的。
For accessing dictionary via index you may use OrderedDictionary
. One disadvantage is that is is not generic.
这篇关于可以通过索引访问Expandoobject属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!