Exemplo n.º 1
0
        public new void VisitUnary(UnaryExpression expr_)
        {
            Type           expType = expr_.GetType();
            Type           type_   = expr_.GetType().BaseType;
            ExpressionType ndType  = expr_.NodeType;

            if (ndType == ExpressionType.Convert)
            {
                if (expr_.Operand.Type == typeof(DateTime))
                {
                    Expression expr    = Expression.Convert(expr_.Operand, expr_.Operand.Type);
                    DateTime   exprCpl = Expression.Lambda <Func <DateTime> >(expr).Compile()();

                    nestedProperties.Push("'");
                    nestedProperties.Push(exprCpl.ToString(ConfigurationManager.AppSettings["OrientDateTime"]));
                    nestedProperties.Push("'");
                }
                if (expr_.Operand.Type == typeof(int))
                {
                    int?exprCpl = Expression.Lambda <Func <int?> >(expr_).Compile()();
                    nestedProperties.Push(exprCpl.ToString());
                }
                if (expr_.Operand.Type == typeof(double))
                {
                    double?exprCpl = Expression.Lambda <Func <double?> >(expr_).Compile()();
                    nestedProperties.Push(exprCpl.ToString());
                }
            }
        }
Exemplo n.º 2
0
 //
 // Summary:
 //     Visits the children of the System.Linq.Expressions.UnaryExpression.
 //
 // Parameters:
 //   node:
 //     The expression to visit.
 //
 // Returns:
 //     The modified expression, if it or any subexpression was modified; otherwise,
 //     returns the original expression.
 protected override Expression VisitUnary(UnaryExpression node)
 {
     Console.WriteLine("VisitUnary:");
     Console.WriteLine('\t' + node.GetType().ToString());
     Console.WriteLine('\t' + node.ToString());
     return(base.VisitUnary(node));
 }
Exemplo n.º 3
0
        public void TypedThrowNullSameAsRethrowInterpreted()
        {
            UnaryExpression rethrow   = Expression.Rethrow(typeof(int));
            UnaryExpression nullThrow = Expression.Throw(null, typeof(int));

            Assert.Equal(rethrow.GetType(), nullThrow.GetType());
            TryExpression rethrowTwice = Expression.TryCatch(
                Expression.TryCatch(
                    Expression.Throw(Expression.Constant(new TestException()), typeof(int)),
                    Expression.Catch(typeof(TestException), rethrow)
                    ),
                Expression.Catch(typeof(TestException), nullThrow)
                );
            Action doRethrowTwice = Expression.Lambda <Action>(rethrowTwice).Compile(true);

            Assert.Throws <TestException>(() => doRethrowTwice());
        }
Exemplo n.º 4
0
        public void ThrowNullSameAsRethrow()
        {
            UnaryExpression rethrow   = Expression.Rethrow();
            UnaryExpression nullThrow = Expression.Throw(null);

            Assert.Equal(rethrow.GetType(), nullThrow.GetType());
            TryExpression rethrowTwice = Expression.TryCatch(
                Expression.TryCatch(
                    Expression.Throw(Expression.Constant(new TestException())),
                    Expression.Catch(typeof(TestException), rethrow)
                    ),
                Expression.Catch(typeof(TestException), nullThrow)
                );
            Action doRethrowTwice = Expression.Lambda <Action>(rethrowTwice).Compile(false);

            Assert.Throws <TestException>(doRethrowTwice);
        }
Exemplo n.º 5
0
 protected override Expression VisitUnary(UnaryExpression node)
 {
     throw new NotSupportedException(node.GetType().Name);
 }
Exemplo n.º 6
0
 protected override Expression VisitUnary(UnaryExpression node)
 {
     throw new NotSupportedException($"Node type {node.GetType().Name} is not supported.");
 }
 protected override void WriteUnary(UnaryExpression expr) =>
 WriteUnary(expr.NodeType, "Operand", expr.Operand, expr.Type, expr.GetType().Name);
Exemplo n.º 8
0
        static Node Unary(UnaryExpression e)
        {
            switch (e.NodeType)
            {
            case ExpressionType.Convert:
                return(new UnaryNode
                {
                    Prefix = "(" + NameOfType(e.Type) + ")(",
                    Operand = Parse(e.Operand),
                    Suffix = ")",
                    PrefixValue = GetValue(e)
                });

            case ExpressionType.Not:
                return(new UnaryNode {
                    Prefix = "!", Operand = Parse(e.Operand), PrefixValue = GetValue(e)
                });

            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
                return(new UnaryNode {
                    Prefix = "-", Operand = Parse(e.Operand), PrefixValue = GetValue(e)
                });
            }
            throw new ArgumentOutOfRangeException("e",
                                                  string.Format("Can't handle UnaryExpression expression of class {0} and type {1}", e.GetType().Name,
                                                                e.NodeType));
        }
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.</returns>
 protected override Expression VisitUnary(UnaryExpression node)
 {
     throw new NotSupportedException(string.Format(Resources.EX_PROCESS_NODE_NOT_SUPPORT, node.GetType().Name));
 }
Exemplo n.º 10
0
        protected override Expression VisitUnary(UnaryExpression node)
        {
            switch (node.NodeType)
            {
            case ExpressionType.Convert:
            case ExpressionType.Unbox:
            {
                this._writer.Write("( ");
                this._writer.Write(node.Type);
                this._writer.Write(" )");
                break;
            }

            case ExpressionType.ConvertChecked:
            {
                this._writer.Write("checked( ( ");
                this._writer.Write(node.Type);
                this._writer.Write(" )");
                break;
            }

            case ExpressionType.Decrement:
            {
                this._writer.Write("`decr`( ");
                break;
            }

            case ExpressionType.Increment:
            {
                this._writer.Write("`incr`( ");
                break;
            }

            case ExpressionType.IsFalse:
            {
                this._writer.Write("`false`( ");
                break;
            }

            case ExpressionType.IsTrue:
            {
                this._writer.Write("`true`( ");
                break;
            }

            case ExpressionType.Negate:
            {
                this._writer.Write("( -( ");
                break;
            }

            case ExpressionType.NegateChecked:
            {
                this._writer.Write("checked( -( ");
                break;
            }

            case ExpressionType.OnesComplement:
            {
                this._writer.Write("~(");
                break;
            }

            case ExpressionType.PreDecrementAssign:
            {
                this._writer.Write("--(");
                break;
            }

            case ExpressionType.PreIncrementAssign:
            {
                this._writer.Write("++(");
                break;
            }

            case ExpressionType.Throw:
            {
                this._writer.Write("throw ( ");
                break;
            }

            case ExpressionType.UnaryPlus:
            {
                this._writer.Write("( +( ");
                break;
            }

            case ExpressionType.ArrayLength:
            case ExpressionType.PostDecrementAssign:
            case ExpressionType.PostIncrementAssign:
            case ExpressionType.TypeAs:
            case ExpressionType.TypeIs:
            {
                this._writer.Write("( ");
                break;
            }

            default:
            {
                throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "Unary operation {0}(NodeType:{1}) is not supported. Expression tree:{2}", node.GetType().Name, node.NodeType, node));
            }
            }

            this.Visit(node.Operand);

            switch (node.NodeType)
            {
            case ExpressionType.ArrayLength:
            {
                this._writer.Write(" ).Length");
                break;
            }

            case ExpressionType.ConvertChecked:
            case ExpressionType.Decrement:
            case ExpressionType.Increment:
            case ExpressionType.IsFalse:
            case ExpressionType.IsTrue:
            case ExpressionType.OnesComplement:
            case ExpressionType.PreDecrementAssign:
            case ExpressionType.PreIncrementAssign:
            case ExpressionType.Throw:
            {
                this._writer.Write(" )");
                break;
            }

            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
            case ExpressionType.UnaryPlus:
            {
                this._writer.Write(" ) )");
                break;
            }

            case ExpressionType.PostDecrementAssign:
            {
                this._writer.Write(" )--");
                break;
            }

            case ExpressionType.PostIncrementAssign:
            {
                this._writer.Write(" )++");
                break;
            }

            case ExpressionType.TypeAs:
            {
                this._writer.Write(") as ");
                this._writer.Write(node.Type);
                break;
            }

            case ExpressionType.TypeIs:
            {
                this._writer.Write(") is ");
                this._writer.Write(node.Type);
                break;
            }
            }

            return(node);
        }
Exemplo n.º 11
0
        Node ParseExpression(UnaryExpression e)
        {
            switch (e.NodeType)
            {
            case ExpressionType.Convert:
                return(new UnaryNode {
                    Prefix = "(" + NameOfType(e.Type) + ")", Operand = Parse(e.Operand), PrefixValue = GetValue(e)
                });

            case ExpressionType.Not:
                return(new UnaryNode {
                    Prefix = "!", Operand = Parse(e.Operand), PrefixValue = GetValue(e)
                });

            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
                return(new UnaryNode {
                    Prefix = "-", Operand = Parse(e.Operand), PrefixValue = GetValue(e)
                });

            case ExpressionType.ArrayLength:
                return(new MemberAccessNode {
                    Container = Parse(e.Operand), MemberName = "Length", MemberValue = GetValue(e)
                });
            }
            throw new ArgumentOutOfRangeException("e", string.Format("Can't handle UnaryExpression expression of class {0} and type {1}", e.GetType().Name, e.NodeType));
        }