private static bool IsComparison(Expression expression)
            {
                MethodCallExpression mce = expression as MethodCallExpression;

                if (mce == null)
                {
                    switch (expression.NodeType)
                    {
                    case ExpressionType.Equal:
                    case ExpressionType.LessThan:
                    case ExpressionType.LessThanOrEqual:
                    case ExpressionType.GreaterThan:
                    case ExpressionType.GreaterThanOrEqual:
                    case ExpressionType.NotEqual:
                        return(true);

                    default:
                        return(false);
                    }
                }

                ExpressionType ignored;

                return(MethodCallConverter.GetVBObjectComparisonType(mce, out ignored));
            }
Exemplo n.º 2
0
            protected override Expression VisitMethodCall(MethodCallExpression m)
            {
                if (m.Method.DeclaringType.FullName == "Microsoft.VisualBasic.CompilerServices.Operators" && m.Arguments.Count == 3)
                {
                    ExpressionType comparisonType;
                    if (MethodCallConverter.GetVBObjectComparisonType(m, out comparisonType))
                    {
                        // Translate CompareObject[operator](x, y) to x [operator] y.
                        ReadOnlyCollection <Expression> args = this.Visit(m.Arguments);
                        return(Expression.MakeBinary(comparisonType, args[0], args[1]));
                    }
                }
                else if (m.Method.DeclaringType.FullName == "Microsoft.VisualBasic.Interaction" &&
                         m.Method.Name == "IIf" &&
                         m.Arguments.Count == 3)
                {
                    // Translate VB's "iif(test, truePart, falsePart)" into "test ? truePart : falsePart".
                    ReadOnlyCollection <Expression> args = this.Visit(m.Arguments);
                    return(Expression.Condition(args[0], args[1], args[2]));
                }

                return(base.VisitMethodCall(m));
            }