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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
ExpandoObject
is nothing but a fancy IDictionary
which leverages the DLR.
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).
For accessing dictionary via index you may use OrderedDictionary
. One disadvantage is that is is not generic.
Know more about issues when accessing elements via index from a Dictionary