I am trying to count the dynamic properties of an ExpandoObject.
I have tried
int count = values.ICollection<KeyValuePair<string, Object>>.Count();
but it generates error.
Any help?
UPDATE:
how can i read a property at specific index?
I am trying to count the dynamic properties of an ExpandoObject.
I have tried
int count = values.ICollection<KeyValuePair<string, Object>>.Count();
but it generates error.
Any help?
UPDATE:
how can i read a property at specific index?
Your cast is wrong. Instead of
int count = values.ICollection<KeyValuePair<string, Object>>.Count();
use
int count = ((ICollection<KeyValuePair<string, Object>>)values).Count;
You could also cast your object to IDictionary<string, object>
, then it becomes shorter:
int count = ((IDictionary<string, object>)values).Count
To read a property at specific index, you can use the ElementAt
extension method:
var valueAt5 = ((IDictionary<string, object>)values).ElementAt(5).Value
ExpandoObject
implements IDictionary<string, object>
, thus you need to cast it to this interface and you'll be able to access IDictionary<TKey, TValue>.Count
.