Skip to content

Unable to assign a value to a dynamic property #340

@philrawlings

Description

@philrawlings

I get an exception when trying to assign a value on an expando object:
ParseException = Expression must be writable (at index 9)

var target = new Interpreter();
target.EnableAssignment(AssignmentOperators.AssignmentEqual);

dynamic parent = new ExpandoObject();
parent.X = 3;  // Same exception whether this property exists or not

var parameters = new[] {
    new Parameter("parent", parent)
};

var expression = "parent.X = 10";

// ParseException = Expression must be writable (at index 9)
target.Parse(expression, parameters);

I tried using a non-dynamic object and that works fine:

var target = new Interpreter();
target.EnableAssignment(AssignmentOperators.AssignmentEqual);

var parent = new SimpleNumericAssignment(); // has a get/set integer property "X"

var parameters = new[] {
    new Parameter("parent", parent)
};

var expression = "parent.X = 10";

var myFunc = target.Parse(expression, parameters);
myFunc.Invoke(parameters);

Am I doing something wrong? Is this a known limitation and/or is there a way to work around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions