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

Problem evaluating function with Scope

Sep 4, 2015 at 4:35 PM
Dear All,
if I try to evaluate

Math.Pow(2,2)

it returns 4 (OK!!!)

but when I try to evaluate this function:

Math.Pow(p,2)

this exception is thrown :

cannot resolve memeber Pow on Type RunTImeType at line 1 char 12.

Math is in TypeRegistry when p is set by evaluating:

p=2

afterthat the Scope is updated correctly.

What is wrong?

Many thank for your replies!

Andrea
PS: Math is in TypeRegistry when p is set by evaluating:

p=2

afterthat the Scope is updated correctly.

I've set "p" = 2 and it is in the Scope (Scope is a DynamicObject)
Dec 24, 2015 at 11:28 AM
The Code Used to perform the test of the previous message was:

_
        _registry = new TypeRegistry();

        _registry.RegisterDefaultTypes();

        _registry.RegisterType<ModelDynamicObject>();

        _expressionCompiler = new CompiledExpression() { TypeRegistry = _registry };
        _expressionCompiler.StringToParse = code;

        _expressionCompiler.ScopeParse();

        var func = _expressionCompiler.ScopeCompile();_
And code will be respectively : "p=2" that it work!
and Math.Pow(p,2) that doesn't wok!!

Thank you!
Merry Christmas.
Andrea
Jun 16, 2016 at 10:51 AM
Hi, I met with similar problem, have you solved it?
Sep 16, 2016 at 12:54 AM
The following code should work fine:
        class Container
        {
            public double p { get; set; }
        }

        static void Test()
        {
            var _registry = new TypeRegistry();

            _registry.RegisterDefaultTypes();

            var _expressionCompiler = new CompiledExpression() { TypeRegistry = _registry };
            _expressionCompiler.StringToParse = "Math.Pow(p, 2)";

            var func = _expressionCompiler.ScopeCompile<Container>();
            var k = new Container();
            k.p = 2;
            Console.WriteLine(func(k));
            Console.ReadLine();
        }
Note that it works when the scope type is defined and not a dynamic type.