Is it possible to access Expandoobject properties by index?

扶醉桌前 提交于 2019-12-11 09:11:25

问题


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



来源:https://stackoverflow.com/questions/25177836/is-it-possible-to-access-expandoobject-properties-by-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!