vendredi 6 février 2015

Method member access on dynamic object invokes TryGetMember

I have a custom dynamic objects which is internally just a dictionary, but allows to access it's values as if their being compile time properties.


It's (more or less) just this:



public class Dummy : DynamicObject, IEnumerable<KeyValuePair<string, object>>
{
private readonly Dictionary<string, object> _values...

public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _values[binder.Name];
return true;
}
...


Setting and getting 'properties' works fine, but since my object technically implements IEnumerable<'1>, I'd like to call methods from IEnumerable<'1> on it.


However, whenever I call e.g. Count(), TryGetMember gets invoked which of course doesn't make sense:



The key 'Count()' was not present in the dictionary.


Is there a way to get around this?






Aucun commentaire:

Enregistrer un commentaire