private static Expression CompileObjectAssignment(Obj variable, Base value, Scope scope) { var tempName = scope.FreeVariableName("ref"); var expressions1 = new List<Base> { new Assign {Variable = NewValue(tempName), Value = value} }; var propNames = CompileToNames(variable); var assignments = propNames.Select(prop => new Assign {Variable = NewValue(prop), Value = NewValue(tempName, prop)}); expressions1.AddRange(assignments); var expressions = expressions1.Select(expr => Compile(expr, scope)); return Expression.Block(expressions); }
private static Expression CompileObj(Obj obj, Scope scope) { var temp = scope.FreeVariable("obj"); var expressions = new List<Expression> { Expression.Assign(temp, Expression.New(ExpandoConstructor)) }; foreach (var @base in obj.Properties) { var property = @base as Assign; foreach (var name in CompileToNames(property.Variable)) { var expression = Compile(property.Value, scope); expressions.Add(Expression.Dynamic(scope.GetRuntime().SetMemberBinders.Get(name), typeof(object), temp, expression)); } } expressions.Add(temp); return Expression.Block(expressions); }