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

Expression must be writable error. #321

Open
mercurial-moon opened this issue Oct 27, 2024 · 1 comment
Open

Expression must be writable error. #321

mercurial-moon opened this issue Oct 27, 2024 · 1 comment

Comments

@mercurial-moon
Copy link

Code

var ipt = new Interpreter()
ipt.SetVariable("a", 0);
ipt.SetVariable("b", 10);
ipt.SetVariable("c", 20);
var result = ipt.Eval("a = b + c"); // <= Error: DynamicExpresso.Exceptions.ParseException: 'Expression must be writable (at index 2).'

also tried changing first line to

var ipt = new Interpreter().EnableAssignment(AssignmentOperators.All);

but result is same.
if i remove the assignment it works

var result = ipt.Eval("b + c"); // 30
@davideicardi
Copy link
Member

Yes, sorry, this is not supported. Variables are "read only". What I think you can do is create a object and assign one of its property. Something like:

var ipt = new Interpreter().EnableAssignment(AssignmentOperators.All);
ipt.SetVariable("registry", someObject);
ipt.SetVariable("b", 10);
ipt.SetVariable("c", 20);
var result = ipt.Eval("registry.a = b + c");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants