Esempio n. 1
0
        /// <summary>Visits an unary expression.</summary>
        /// <param name="expression">Expression to be visited.</param>
        /// <returns>Expression visited</returns>
        protected override System.Linq.Expressions.Expression VisitUnary(System.Linq.Expressions.UnaryExpression expression)
        {
            MethodNames operatorName;

            System.Linq.Expressions.ExpressionType expressionType = expression.NodeType;
            switch (expression.NodeType)
            {
            case System.Linq.Expressions.ExpressionType.Convert:
            case System.Linq.Expressions.ExpressionType.TypeAs:
                return(Visit(expression.Operand));

            default:
                string methodName = Enum.GetNames(typeof(MethodNames)).Where(item => item == expressionType.ToString()).FirstOrDefault();
                if (!System.String.IsNullOrEmpty(methodName))
                {
                    operatorName = (MethodNames)Enum.Parse(typeof(MethodNames), methodName);
                }
                else
                {
                    return(base.VisitUnary(expression));
                }

                break;
            }

            UnaryOperator unaryOperator = new UnaryOperator(operatorName);

            HandleComponent(unaryOperator);

            Visit(expression.Operand);
            CleanupComponent(_lastComponent);

            _lastComponent = unaryOperator;
            return(expression);
        }
Esempio n. 2
0
        private string Visit(System.Linq.Expressions.ExpressionType op)
        {
            switch (op)
            {
            case System.Linq.Expressions.ExpressionType.Add: return("+");

            case System.Linq.Expressions.ExpressionType.AddAssign: return("+=");

            case System.Linq.Expressions.ExpressionType.AddAssignChecked: break;

            case System.Linq.Expressions.ExpressionType.AddChecked: break;

            case System.Linq.Expressions.ExpressionType.And: return("&");

            case System.Linq.Expressions.ExpressionType.AndAlso: return("&&");

            case System.Linq.Expressions.ExpressionType.AndAssign: return("&=");

            case System.Linq.Expressions.ExpressionType.ArrayIndex: break;

            case System.Linq.Expressions.ExpressionType.ArrayLength: break;

            case System.Linq.Expressions.ExpressionType.Assign: return("=");

            case System.Linq.Expressions.ExpressionType.Block: break;

            case System.Linq.Expressions.ExpressionType.Call: break;

            case System.Linq.Expressions.ExpressionType.Coalesce: return("??");

            case System.Linq.Expressions.ExpressionType.Conditional: break;

            case System.Linq.Expressions.ExpressionType.Constant: break;

            case System.Linq.Expressions.ExpressionType.Convert: break;

            case System.Linq.Expressions.ExpressionType.ConvertChecked: break;

            case System.Linq.Expressions.ExpressionType.DebugInfo: break;

            case System.Linq.Expressions.ExpressionType.Decrement: break;

            case System.Linq.Expressions.ExpressionType.Default: break;

            case System.Linq.Expressions.ExpressionType.Divide: return("/");

            case System.Linq.Expressions.ExpressionType.DivideAssign: return("/=");

            case System.Linq.Expressions.ExpressionType.Dynamic: break;

            case System.Linq.Expressions.ExpressionType.Equal: return("==");

            case System.Linq.Expressions.ExpressionType.ExclusiveOr: return("^");

            case System.Linq.Expressions.ExpressionType.ExclusiveOrAssign: return("^=");

            case System.Linq.Expressions.ExpressionType.Extension: break;

            case System.Linq.Expressions.ExpressionType.Goto: break;

            case System.Linq.Expressions.ExpressionType.GreaterThan: return(">");

            case System.Linq.Expressions.ExpressionType.GreaterThanOrEqual: return(">=");

            case System.Linq.Expressions.ExpressionType.Increment: break;

            case System.Linq.Expressions.ExpressionType.Index: break;

            case System.Linq.Expressions.ExpressionType.Invoke: break;

            case System.Linq.Expressions.ExpressionType.IsFalse: break;

            case System.Linq.Expressions.ExpressionType.IsTrue: break;

            case System.Linq.Expressions.ExpressionType.Label: break;

            case System.Linq.Expressions.ExpressionType.Lambda: break;

            case System.Linq.Expressions.ExpressionType.LeftShift: return("<<");

            case System.Linq.Expressions.ExpressionType.LeftShiftAssign: return("<<=");

            case System.Linq.Expressions.ExpressionType.LessThan: return("<");

            case System.Linq.Expressions.ExpressionType.LessThanOrEqual: return("<=");

            case System.Linq.Expressions.ExpressionType.ListInit: break;

            case System.Linq.Expressions.ExpressionType.Loop: break;

            case System.Linq.Expressions.ExpressionType.MemberAccess: break;

            case System.Linq.Expressions.ExpressionType.MemberInit: break;

            case System.Linq.Expressions.ExpressionType.Modulo: return("%");

            case System.Linq.Expressions.ExpressionType.ModuloAssign: return("%=");

            case System.Linq.Expressions.ExpressionType.Multiply: return("*");

            case System.Linq.Expressions.ExpressionType.MultiplyAssign: return("*=");

            case System.Linq.Expressions.ExpressionType.MultiplyAssignChecked: break;

            case System.Linq.Expressions.ExpressionType.MultiplyChecked: break;

            case System.Linq.Expressions.ExpressionType.Negate: return("-");

            case System.Linq.Expressions.ExpressionType.NegateChecked: break;

            case System.Linq.Expressions.ExpressionType.New: break;

            case System.Linq.Expressions.ExpressionType.NewArrayBounds: break;

            case System.Linq.Expressions.ExpressionType.NewArrayInit: break;

            case System.Linq.Expressions.ExpressionType.Not: return("!");

            case System.Linq.Expressions.ExpressionType.NotEqual: return("!=");

            case System.Linq.Expressions.ExpressionType.OnesComplement: return("~");

            case System.Linq.Expressions.ExpressionType.Or: return("|");

            case System.Linq.Expressions.ExpressionType.OrAssign: return("|=");

            case System.Linq.Expressions.ExpressionType.OrElse: return("||");

            case System.Linq.Expressions.ExpressionType.Parameter: break;

            case System.Linq.Expressions.ExpressionType.PostDecrementAssign: return("--");

            case System.Linq.Expressions.ExpressionType.PostIncrementAssign: return("++");

            case System.Linq.Expressions.ExpressionType.Power: break;

            case System.Linq.Expressions.ExpressionType.PowerAssign: break;

            case System.Linq.Expressions.ExpressionType.PreDecrementAssign: return("--");

            case System.Linq.Expressions.ExpressionType.PreIncrementAssign: return("++");

            case System.Linq.Expressions.ExpressionType.Quote: break;

            case System.Linq.Expressions.ExpressionType.RightShift: return(">>");

            case System.Linq.Expressions.ExpressionType.RightShiftAssign: return(">>=");

            case System.Linq.Expressions.ExpressionType.RuntimeVariables: break;

            case System.Linq.Expressions.ExpressionType.Subtract: return("-");

            case System.Linq.Expressions.ExpressionType.SubtractAssign: return("-=");

            case System.Linq.Expressions.ExpressionType.SubtractAssignChecked: break;

            case System.Linq.Expressions.ExpressionType.SubtractChecked: break;

            case System.Linq.Expressions.ExpressionType.Switch: break;

            case System.Linq.Expressions.ExpressionType.Throw: break;

            case System.Linq.Expressions.ExpressionType.Try: break;

            case System.Linq.Expressions.ExpressionType.TypeAs: break;

            case System.Linq.Expressions.ExpressionType.TypeEqual: break;

            case System.Linq.Expressions.ExpressionType.TypeIs: break;

            case System.Linq.Expressions.ExpressionType.UnaryPlus: break;

            case System.Linq.Expressions.ExpressionType.Unbox: break;

            default: break;
            }
            throw new NotImplementedException(op.ToString());
        }
Esempio n. 3
0
        /// <summary>Visits a binary expression.</summary>
        /// <param name="expression">Expression to be visited.</param>
        /// <returns>Expression visited</returns>
        protected override System.Linq.Expressions.Expression VisitBinary(System.Linq.Expressions.BinaryExpression expression)
        {
            MethodNames operatorName;

            System.Linq.Expressions.ExpressionType expressionType = expression.NodeType;
            switch (expression.NodeType)
            {
            case System.Linq.Expressions.ExpressionType.OrElse:
                expressionType = System.Linq.Expressions.ExpressionType.Or;
                goto default;

            case System.Linq.Expressions.ExpressionType.AndAlso:
                expressionType = System.Linq.Expressions.ExpressionType.And;
                goto default;

            default:
                string methodName = Enum.GetNames(typeof(MethodNames)).Where(item => item == expressionType.ToString()).FirstOrDefault();
                if (!System.String.IsNullOrEmpty(methodName))
                {
                    operatorName = (MethodNames)Enum.Parse(typeof(MethodNames), methodName);
                }
                else
                {
                    return(base.VisitBinary(expression));
                }

                break;
            }

            BinaryOperator binaryOperator = new BinaryOperator(operatorName);

            HandleComponent(binaryOperator);

            Visit(expression.Left);
            CleanupComponent(_lastComponent);

            Visit(expression.Right);
            CleanupComponent(_lastComponent);

            _lastComponent = binaryOperator;
            return(expression);
        }