Example #1
0
        private static bool IsEqual(ConstantExpression left, ConstantExpression right)
        {
            if (left.ConstantType != right.ConstantType)
            {
                return(false);
            }

            if (left.ConstantType == ConstantType.Boolean)
            {
                BooleanConstantExpression leftBoolean  = (BooleanConstantExpression)left;
                BooleanConstantExpression rightBoolean = (BooleanConstantExpression)right;

                return(leftBoolean.Value == rightBoolean.Value);
            }
            else if (left.ConstantType == ConstantType.Integer)
            {
                IntegerConstantExpression leftInteger  = (IntegerConstantExpression)left;
                IntegerConstantExpression rightInteger = (IntegerConstantExpression)right;

                return(leftInteger.Value == rightInteger.Value);
            }
            else if (left.ConstantType == ConstantType.String)
            {
                StringConstantExpression leftString  = (StringConstantExpression)left;
                StringConstantExpression rightString = (StringConstantExpression)right;

                return(string.Equals(leftString.Value, rightString.Value, StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                throw new EnableInfoException(string.Format(CultureInfo.InvariantCulture, "{0} is not supported.", left.ConstantType));
            }
        }
Example #2
0
        private BooleanConstantExpression VisitInFunction(ReadOnlyCollection <Expression> args)
        {
            if (args != null && args.Count >= 2)
            {
                // The EnableInfo documentation states that the 'in' function returns true
                // if the first parameter is equal to at least one of the following parameters.

                ConstantExpression first = Visit(args[0]) as ConstantExpression;
                if (first != null)
                {
                    if (first.ConstantType == ConstantType.String)
                    {
                        string firstParameter = ((StringConstantExpression)first).Value;

                        for (int i = 1; i < args.Count; i++)
                        {
                            StringConstantExpression parameter = Visit(args[i]) as StringConstantExpression;
                            if (parameter != null && string.Equals(firstParameter, parameter.Value, StringComparison.OrdinalIgnoreCase))
                            {
                                return(BooleanConstantExpression.True);
                            }
                        }
                    }
                    else if (first.ConstantType == ConstantType.Integer)
                    {
                        int firstParameter = ((IntegerConstantExpression)first).Value;

                        for (int i = 1; i < args.Count; i++)
                        {
                            IntegerConstantExpression parameter = Visit(args[i]) as IntegerConstantExpression;
                            if (parameter != null && firstParameter == parameter.Value)
                            {
                                return(BooleanConstantExpression.True);
                            }
                        }
                    }
                    else if (first.ConstantType == ConstantType.Boolean)
                    {
                        bool firstParameter = ((BooleanConstantExpression)first).Value;

                        for (int i = 1; i < args.Count; i++)
                        {
                            BooleanConstantExpression parameter = Visit(args[i]) as BooleanConstantExpression;
                            if (parameter != null && firstParameter == parameter.Value)
                            {
                                return(BooleanConstantExpression.True);
                            }
                        }
                    }
                }
            }

            return(BooleanConstantExpression.False);
        }