Is it possible to access Expandoobject properties

2019-07-31 10:33发布

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条回答
Luminary・发光体
2楼-- · 2019-07-31 10:59

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

查看更多
登录 后发表回答