问题
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