Skip to content

Validating Syntax of Dynamic Expressions without parameter values #326

Answered by davideicardi
aerott asked this question in Q&A
Discussion options

You must be logged in to vote

You don't have to specify the parameter value in order to parse the expression.
Here an example:

var target = new Interpreter();

var parameters = new[] {
	new Parameter("x", typeof(int)),
	new Parameter("y", typeof(int))
};

var myFunc = target.Parse("x + y", parameters);

Assert.AreEqual(30, myFunc.Invoke(23, 7));
Assert.AreEqual(30, myFunc.Invoke(32, -2));

If the expression is not valid, it will throw in the Parse function.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aerott
Comment options

@davideicardi
Comment options

Answer selected by aerott
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants