Can variables created in hosting scope be written to?

May 5, 2009 at 4:53 AM

I have been playing around with the DLR, and have been trying to get a handle on how far it can be extended into the CLR...

Question: I declare a variable X in a scope that I pass into the Execute function. After finally finding the post about how to access these variables since Ast.Read() is no longer with us, I have the following.

            Expression ISymCall = Expression.Call(typeof(SymbolTable).GetMethod("StringToId"), Expression.Constant("x"));
            Expression varX = Expression.Call(block.Parameters[0], "LookupName",
                new Type[] { }, block.Parameters[1], ISymCall);

This works perfectly for reading the value of x, but if I try and use varX in for instance the Expression.Assign function as the destination, I get an Exception that varX is not writeable. Is there a way around this, or is the simplest answer to wrap everything in a CLR class, pass in an instance of the class, and use methods to modify the value?
May 5, 2009 at 6:11 AM
I'm not sure that I understand entirely what you're doing, but the counterpart of Scope.LookupName is Scope.SetName -- you can write a value into a Scope object with a separate Call expression that uses SetName.
May 5, 2009 at 6:59 PM
I never thought about that... Thanks