This project is read-only.

CanWrite in Microsoft.Linq.Expressions.Expression ?

May 13, 2009 at 1:46 PM


does anyone know what the deal is with Microsoft.Linq.Expressions.Expression.CanWrite in the DLR and IPy 2.0.1 source: Does this mean that System.Linq.Expressions.Expression will in the future (.NET 4) also no longer be guaranteed to be immutable ? This would probably make some things more efficient but might break some assumptions so it would be interesting to know this for planning the future implementation our remotion open source framework Linq provider.

Thanks in advance,




May 13, 2009 at 3:06 PM

If you look at more recent sources --, for example -- you'll see that CanWrite is no longer present. Making expression trees mutable would indeed be a breaking change, so it's not likely that would ever happen.

May 13, 2009 at 3:20 PM

Hi Curt,

thanks for clearing this up; it would indeed have been surprising if that had happened.

On the other hand I think that there are people who are not happy with being forced to use immutable Expression|s, so the question remains valid.
I suppose, there probably also was a reason why the CanWrite property was in there up to IPy 2.0.1 ...
In addition it could have been that the DLR/IPy was moving away from using the same Expression implementation as Linq.

Well, enough retro-speculation, thanks again,



May 13, 2009 at 3:36 PM

"CanWrite" never meant that the tree was not immutable -- it meant that the expression represented by a particular node could have a value stored into it. Parameter/variable expressions, index expressions and member access expressions are all potentially writable, because you can store values into them when the tree is executed. So an assignment expression (for instance) will assert that the left-hand-side of the assignment is writable -- otherwise, you can't perform the assignment.

May 13, 2009 at 3:59 PM

Hi Curt,

I see. Thanks for clearing up yet again.
The "CanWrite"-Intellisense-<summary>: "Indicates that the node can be written" seemed to indicate a writeable node to us... ;-)



May 14, 2009 at 12:23 AM

As Curt clarified, the CanWrite property was used when we allowed reducible nodes and thought we’d have a more general LHS story for ET nodes.  The property simply indicated the node could be used as the Left ET of a BinaryExpression node with node kind Assign, or as the argument to a ref parameter.  When we removed the faux generality for CLR 4.0, we removed a couple unnecessary properties that went with the more general plan.  A more general plan is on the table for ETs v3, but no more thinking has gone into that at this point since we’re focused on cleaning up for CLR 4.0 release.



May 15, 2009 at 3:51 PM

Hi Bill,

thanks for elaborating. I think we know now were we stand and are looking forward to what ETs v3 will bring :-)