Multiple property calls are ignored in IDynamicObject implementation
I implemented IDynamicObject in C # 4, returned a custom MetaObject subclass that makes a simple getter / setter sink into a dictionary. Not rocket science.
If I do this:
dynamic foo = new DynamicFoo();
foo.Name = "Joe";
foo.Name = "Fred";
Console.WriteLine(foo.Name);
Then "Joe" is printed to the console ... the second call to the "Name" setter is never called (never actually part of my custom dispatcher code).
I know DLR does caching on sites, but I assumed that would not apply here. Does anyone know what's going on?
source to share
No matter what MetaObject you return from (Bind), SetMember will be cached and reused in this case. You have 2 dynamic sites that make bundles. The 1st call will cache the result in the L2 cache, which the second site will fetch before asking you to create a new rule.
Thus, any MetaObject returned must include an expression tree that will update the value. For example, it should do something like:
return a new MetaObject (Expression.AssignProperty (this.Expression, value.Expression), Restrictions.TypeRestriction (this.Expression, this.Value.GetType ());
source to share