Example #1
0
        public override System.Linq.Expressions.Expression TransformRead()
        {
            if (ExpressionType == UnaryOperator.New)
            {
                var ie = Operand as InvokeExpression;
                if (ie != null)
                {
                    return(System.Linq.Expressions.Expression.Dynamic(
                               LanguageContext.CreateCreateBinder(new System.Dynamic.CallInfo(ie.Arguments.Count)),
                               typeof(object),
                               ie.TransformTargetAndArguments().Item1
                               ));
                }
                else
                {
                    throw new InvalidOperationException("new 演算子を適用できるのは関数呼び出しのみです。");
                }
            }
            if (ExpressionType == UnaryOperator.Delete)
            {
                return(Operand.TransformDelete());
            }
            if (ExpressionType == UnaryOperator.AccessPropertyObject)
            {
                return(Operand.TransformGetProperty());
            }
            var target = Operand.TransformRead();

            if (ExpressionType == UnaryOperator.PostDecrementAssign || ExpressionType == UnaryOperator.PostIncrementAssign)
            {
                var v = System.Linq.Expressions.Expression.Variable(typeof(object));
                return(System.Linq.Expressions.Expression.Block(new[] { v },
                                                                System.Linq.Expressions.Expression.Assign(v, target),
                                                                Operand.TransformWrite(DoUnaryOperation(LanguageContext, ExpressionType, v)),
                                                                v
                                                                ));
            }
            else
            {
                var exp = DoUnaryOperation(LanguageContext, ExpressionType, target);
                if (ExpressionType == UnaryOperator.PreIncrementAssign || ExpressionType == UnaryOperator.PreDecrementAssign)
                {
                    return(Operand.TransformWrite(exp));
                }
                return(exp);
            }
        }