Skip to content

Conversation

metoule
Copy link
Contributor

@metoule metoule commented Mar 27, 2025

This allows to write:

dynamic dyn = new ExpandoObject();
dyn.Foo = new int[5];

var interpreter = new Interpreter().SetVariable("dyn", (object)dyn);
interpreter.Eval("dyn.Foo[2] = 5");
interpreter.Eval("dyn.Bar = \"foo\"");

Assert.That(dyn.Foo[2], Is.EqualTo(5));
Assert.That(dyn.Bar, Is.EqualTo("foo"));

The fix is bit tricky: when we parse the assignment, the left operand is a dynamic GetMember expression, which can't be assigned via an Expression.Assign. We must instead change the dynamic expression from a GetMember to a SetMember. Those bindings are performed via our Late binders.

We fix the issue by adding a new interface IConvertibleToWritableBinder that can convert the read binder to a write binder.

Fixes #340

@metoule metoule requested a review from davideicardi as a code owner March 27, 2025 22:13
@metoule metoule merged commit 5656777 into dynamicexpresso:master Mar 30, 2025
2 checks passed
@metoule metoule deleted the fix_340 branch March 30, 2025 14:15
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

Successfully merging this pull request may close these issues.

Unable to assign a value to a dynamic property
2 participants