This project has moved and is read-only. For the latest updates, please go here.

Problem Evaluating on Dynamic Objec

Jul 23, 2015 at 3:05 PM
Dear All,

I generate a class
public class Vector
{
     public double Norm()
     { return 1;}
}
Then I create a ExpandoObject and add to it a Vector:
Vector v = new Vector();
dynamic CC = new ExpandoObject();
CC.v = v;
_registry.RegisterSymbol("CC", CC);
_registry.RegisterType("Vector",typeof(Vector));
When I call the following code :
var _expressionCompiler = new CompiledExpression("CC.v.Norm()) { TypeRegistry = _registry }
_expressionCompiler.Eval();
the following exception is throw :

Cannot resolve member "Norm" on type "Object" at line 1 char 10

What I'm doing wrong?

Many thanks for your help.

Andrea
Jul 25, 2015 at 3:02 PM
The code is right, there just happens to be a bug I introduced when I changed the way dynamics are handled.

dynamic variables have a runtime type of Object. I used to assume all objects could be dynamic, but this led to inconsistent behavior. Also, my dynamic type-checking was inherently wrong. In my latest commit I have added some better code to handle this, but you still have to make sure the type you registered is of type ExpandoObject. I'll try to replicate the issue and post some code that is working with the latest commit.

I don't have a binary version quite ready for release yet, so you will have to work with compiling the latest source for now.
Jul 27, 2015 at 10:35 AM
RupertAvery wrote:
The code is right, there just happens to be a bug I introduced when I changed the way dynamics are handled.

dynamic variables have a runtime type of Object. I used to assume all objects could be dynamic, but this led to inconsistent behavior. Also, my dynamic type-checking was inherently wrong. In my latest commit I have added some better code to handle this, but you still have to make sure the type you registered is of type ExpandoObject. I'll try to replicate the issue and post some code that is working with the latest commit.

I don't have a binary version quite ready for release yet, so you will have to work with compiling the latest source for now.
Dear RupertAvery ,

Thank you for you reply.

I forgot to mention that the code that I use to replicate the behaviou is different from the code where I found the problem. I use DynamicObject instead of ExpandoObject.

Kind reagrds,
Andrea