Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Ability to do assignment with DynamicExpresso #24

Closed
iiaiiappa opened this issue Oct 29, 2014 · 2 comments
Closed

Feature Request: Ability to do assignment with DynamicExpresso #24

iiaiiappa opened this issue Oct 29, 2014 · 2 comments
Milestone

Comments

@iiaiiappa
Copy link

First of all, thank you for writing DynamicExpresso. It worked as claimed.

I am trying to do assignment. Right now I did the assignment using function call, which is less than ideal.

public class ObjectA { public object Value; }
public class ObjectB { public object Value; }

public void Test1()
{
    var interpreter = new Interpreter();
    var objA = new ObjectA();
    var objB = new ObjectB();
    var data = new Dictionary<string, dynamic>() {
        {"a",objA},
        {"b",objB},
    };
    var paramsList2 = pData.Select(r => new Parameter(r.Key, r.Value)).ToArray();
    interpreter.Eval("a.Value = b.Value", paramsList2);

    Debug.WriteLine(objA.Value);
    Debug.WriteLine(objB.Value);
}

public void Test2()
{
    var interpreter = new Interpreter();
    var objA = new ObjectA();
    var objB = new ObjectB();
    var data = new Dictionary<string, dynamic>() {
        {"a",objA},
        {"b",objB},
    };
    //suppose I set all the SetFunction() here.
    ....
    //Attempting to make Func and Action class working in string expression
    interpreter.Reference(typeof(Func<bool>));
    interpreter.Reference(typeof(Action));
    var paramsList2 = pData.Select(r => new Parameter(r.Key, r.Value)).ToArray();

    //The following won't work because => operator not supported
    interpreter.Eval("new Func<bool>(() => { a.Value = b.Value; return true; })", paramsList2);
    //The following won't work because it returns nothing, and => operator not supported
    interpreter.Eval("new Action(() => { a.Value = b.Value; })", paramsList2);
    //Works, but limited my possibility and flexibility
    interpreter.Eval("SetVal(a,b)", paramsList2);

    Debug.WriteLine(objA.Value);
    Debug.WriteLine(objB.Value);
}
public bool SetVal(dynamic pa, dynamic pb)
{
    pa.Value = pb.Value;
    return true;
}

Thank you!

@davideicardi davideicardi added this to the 1.1 milestone Nov 1, 2014
@davideicardi
Copy link
Member

Ok, I will try to work on it in the future. Thanks for your suggestion.

@davideicardi
Copy link
Member

I have just implemented this feature in 1.1 version. For now just equal assignment operator (=) is supported.

samuelcadieux pushed a commit to samuelcadieux/DynamicExpresso that referenced this issue May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants