Post increment assign binder

Sep 29, 2010 at 11:40 AM


Trying to implement post increment assign, post decrement assign, pre increment assign and pre decrement assign  operators in  a dynamic language.

However the UnaryOperationBinder constructor does not accept any of the pre / post increment / decrement assign operators

It throws an exception:

 "Invalid argument value Parameter name: operation"

Is this a bug or should I be implementing these operators a different way ?


Sep 29, 2010 at 4:29 PM

It's not a bug. See Expression Tree reference sections 4.4.79-82 ( These document post/pre increment/decrment expression tree nodes.

You can implement a++ as a = a + 1, where a+1 is a dynamic unary operator of type ExpressionType.Increment.


Sep 30, 2010 at 10:39 AM


Also having trouble with the AddAssign operator in a dynamic language.

I'm trying to execute AddAssign on a parameter expression which represents a variable in my language.

Since the language is dynamic, the parameter expression is of type Object.

Executing Expression.AddAssign(variable, value) does not work - it says the operation isn't defined for the type Object.

What is the proper way of implementing these operators in dynamic expressions ?

In my language, the Assign operator is handled outside of the binary operation binder (as in Sympl),  Should the AddAssign  be handled in the binary operation binder or outside it like the Assign operator ?


Sep 30, 2010 at 4:24 PM

You can either implement a special binder that performs a += b or you can create an expression tree for a = a + b. In the latter case you'd use a binary operation binder for addition on the right hand side and then just Expression.Assign to the left side. I would only do the former if I needed to optimize some cases. For example, a+=b migth be optimized if a and b are strings and + in your language concatenates them, x[i] += y might be optimizable for hashes and arrays etc.