Exemplo n.º 1
0
        private bool MatchTokens(JToken leftResult, JToken rightResult)
        {
            JValue leftValue  = leftResult as JValue;
            JValue rightValue = rightResult as JValue;

            if (leftValue != null && rightValue != null)
            {
                switch (Operator)
                {
                case QueryOperator.Equals:
                    if (EqualsWithStringCoercion(leftValue, rightValue))
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.NotEquals:
                    if (!EqualsWithStringCoercion(leftValue, rightValue))
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.GreaterThan:
                    if (leftValue.CompareTo(rightValue) > 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.GreaterThanOrEquals:
                    if (leftValue.CompareTo(rightValue) >= 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.LessThan:
                    if (leftValue.CompareTo(rightValue) < 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.LessThanOrEquals:
                    if (leftValue.CompareTo(rightValue) <= 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.Exists:
                    return(true);
                }
            }
            else
            {
                switch (Operator)
                {
                case QueryOperator.Exists:
                // you can only specify primative types in a comparison
                // notequals will always be true
                case QueryOperator.NotEquals:
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        // Token: 0x06001776 RID: 6006 RVA: 0x000724C4 File Offset: 0x000706C4
        private bool MatchTokens(JToken leftResult, JToken rightResult)
        {
            JValue jvalue = leftResult as JValue;

            if (jvalue != null)
            {
                JValue jvalue2 = rightResult as JValue;
                if (jvalue2 != null)
                {
                    switch (this.Operator)
                    {
                    case QueryOperator.Equals:
                        if (BooleanQueryExpression.EqualsWithStringCoercion(jvalue, jvalue2))
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.NotEquals:
                        if (!BooleanQueryExpression.EqualsWithStringCoercion(jvalue, jvalue2))
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.Exists:
                        return(true);

                    case QueryOperator.LessThan:
                        if (jvalue.CompareTo(jvalue2) < 0)
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.LessThanOrEquals:
                        if (jvalue.CompareTo(jvalue2) <= 0)
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.GreaterThan:
                        if (jvalue.CompareTo(jvalue2) > 0)
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.GreaterThanOrEquals:
                        if (jvalue.CompareTo(jvalue2) >= 0)
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.And:
                    case QueryOperator.Or:
                        return(false);

                    case QueryOperator.RegexEquals:
                        if (BooleanQueryExpression.RegexEquals(jvalue, jvalue2))
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.StrictEquals:
                        if (BooleanQueryExpression.EqualsWithStrictMatch(jvalue, jvalue2))
                        {
                            return(true);
                        }
                        return(false);

                    case QueryOperator.StrictNotEquals:
                        if (!BooleanQueryExpression.EqualsWithStrictMatch(jvalue, jvalue2))
                        {
                            return(true);
                        }
                        return(false);

                    default:
                        return(false);
                    }
                }
            }
            QueryOperator @operator = this.Operator;

            if (@operator - QueryOperator.NotEquals <= 1)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public override bool IsMatch(JToken t)
        {
            IEnumerable <JToken> enumerable = JPath.Evaluate(this.Path, t, false);

            foreach (JToken current in enumerable)
            {
                JValue jValue = current as JValue;
                switch (base.Operator)
                {
                case QueryOperator.Equals:
                    if (jValue != null && jValue.Equals(this.Value))
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                case QueryOperator.NotEquals:
                    if (jValue != null && !jValue.Equals(this.Value))
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                case QueryOperator.Exists:
                {
                    bool result = true;
                    return(result);
                }

                case QueryOperator.LessThan:
                    if (jValue != null && jValue.CompareTo(this.Value) < 0)
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                case QueryOperator.LessThanOrEquals:
                    if (jValue != null && jValue.CompareTo(this.Value) <= 0)
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                case QueryOperator.GreaterThan:
                    if (jValue != null && jValue.CompareTo(this.Value) > 0)
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                case QueryOperator.GreaterThanOrEquals:
                    if (jValue != null && jValue.CompareTo(this.Value) >= 0)
                    {
                        bool result = true;
                        return(result);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public override bool IsMatch(JToken t)
        {
            IEnumerable <JToken> pathResult = JPath.Evaluate(Path, t, false);

            foreach (JToken r in pathResult)
            {
                JValue v = r as JValue;
                switch (Operator)
                {
                case QueryOperator.Equals:
                    if (v != null && v.Equals(Value))
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.NotEquals:
                    if (v != null && !v.Equals(Value))
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.GreaterThan:
                    if (v != null && v.CompareTo(Value) > 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.GreaterThanOrEquals:
                    if (v != null && v.CompareTo(Value) >= 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.LessThan:
                    if (v != null && v.CompareTo(Value) < 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.LessThanOrEquals:
                    if (v != null && v.CompareTo(Value) <= 0)
                    {
                        return(true);
                    }
                    break;

                case QueryOperator.Exists:
                    return(true);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public override bool IsMatch(JToken t)
        {
            IEnumerable <JToken> pathResult = JPath.Evaluate(Path, t, false);

            foreach (JToken r in pathResult)
            {
                JValue v = r as JValue;
                if (v != null)
                {
                    switch (Operator)
                    {
                    case QueryOperator.Equals:
                        if (EqualsWithStringCoercion(v, Value))
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.NotEquals:
                        if (!EqualsWithStringCoercion(v, Value))
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.GreaterThan:
                        if (v.CompareTo(Value) > 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.GreaterThanOrEquals:
                        if (v.CompareTo(Value) >= 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.LessThan:
                        if (v.CompareTo(Value) < 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.LessThanOrEquals:
                        if (v.CompareTo(Value) <= 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.Exists:
                        return(true);
                    }
                }
                else
                {
                    switch (Operator)
                    {
                    case QueryOperator.Exists:
                    // you can only specify primative types in a comparison
                    // notequals will always be true
                    case QueryOperator.NotEquals:
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public override bool IsMatch(JToken t)
        {
            IEnumerable <JToken> pathResult = JPath.Evaluate(Path, t, false);

            foreach (JToken r in pathResult)
            {
                JValue v = r as JValue;
                if (v != null)
                {
                    switch (Operator)
                    {
                    case QueryOperator.Equals:
                        if (EqualsWithStringCoercion(v, Value))
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.NotEquals:
                        if (!EqualsWithStringCoercion(v, Value))
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.GreaterThan:
                        if (v.CompareTo(Value) > 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.GreaterThanOrEquals:
                        if (v.CompareTo(Value) >= 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.LessThan:
                        if (v.CompareTo(Value) < 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.LessThanOrEquals:
                        if (v.CompareTo(Value) <= 0)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.Exists:
                        return(true);
                    }
                }
                else
                {
                    switch (Operator)
                    {
                    case QueryOperator.NotEquals:
                        if (Value.Type == JTokenType.Null)
                        {
                            return(true);
                        }
                        break;

                    case QueryOperator.Exists:
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        public void CompareTo_MismatchedTypes()
        {
            JValue v1 = new JValue(1);
            JValue v2 = new JValue("2");

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(1.5);
            v2 = new JValue("2");

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(1.5m);
            v2 = new JValue("2");

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(1.5m);
            v2 = new JValue(2);

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(1.5m);
            v2 = new JValue(2.1);

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(2);
            v2 = new JValue("2");

            Assert.AreEqual(0, v1.CompareTo(v2));
            Assert.AreEqual(0, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(0, v2.CompareTo(v1));
            Assert.AreEqual(0, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(2);
            v2 = new JValue(2m);

            Assert.AreEqual(0, v1.CompareTo(v2));
            Assert.AreEqual(0, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(0, v2.CompareTo(v1));
            Assert.AreEqual(0, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(2f);
            v2 = new JValue(2m);

            Assert.AreEqual(0, v1.CompareTo(v2));
            Assert.AreEqual(0, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(0, v2.CompareTo(v1));
            Assert.AreEqual(0, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(2);
            v2 = new JValue("10");

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue(2);
            v2 = new JValue((object)null);

            Assert.AreEqual(1, v1.CompareTo(v2));
            Assert.AreEqual(1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(-1, v2.CompareTo(v1));
            Assert.AreEqual(-1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue("2");
            v2 = new JValue((object)null);

            Assert.AreEqual(1, v1.CompareTo(v2));
            Assert.AreEqual(1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(-1, v2.CompareTo(v1));
            Assert.AreEqual(-1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue((object)null);
            v2 = new JValue("2");

            Assert.AreEqual(-1, v1.CompareTo(v2));
            Assert.AreEqual(-1, ((IComparable)v1).CompareTo(v2));
            Assert.AreEqual(1, v2.CompareTo(v1));
            Assert.AreEqual(1, ((IComparable)v2).CompareTo(v1));

            v1 = new JValue("2");
            v2 = null;

            Assert.AreEqual(1, v1.CompareTo(v2));
            Assert.AreEqual(1, ((IComparable)v1).CompareTo(v2));

            v1 = new JValue((object)null);
            v2 = null;

            Assert.AreEqual(1, v1.CompareTo(v2));
            Assert.AreEqual(1, ((IComparable)v1).CompareTo(v2));
        }
        public override bool IsMatch(JToken t)
        {
            QueryOperator @operator;
            bool          flag;

            using (IEnumerator <JToken> enumerator = JPath.Evaluate(this.Path, t, false).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    JValue current = enumerator.Current as JValue;
                    if (current == null)
                    {
                        @operator = base.Operator;
                        if (@operator != QueryOperator.NotEquals && @operator != QueryOperator.Exists)
                        {
                            continue;
                        }
                        flag = true;
                        return(flag);
                    }
                    else
                    {
                        @operator = base.Operator;
                        switch (@operator)
                        {
                        case QueryOperator.Equals:
                        {
                            if (!this.EqualsWithStringCoercion(current, this.Value))
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.NotEquals:
                        {
                            if (this.EqualsWithStringCoercion(current, this.Value))
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.Exists:
                        {
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.LessThan:
                        {
                            if (current.CompareTo(this.Value) >= 0)
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.LessThanOrEquals:
                        {
                            if (current.CompareTo(this.Value) > 0)
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.GreaterThan:
                        {
                            if (current.CompareTo(this.Value) <= 0)
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        case QueryOperator.GreaterThanOrEquals:
                        {
                            if (current.CompareTo(this.Value) < 0)
                            {
                                continue;
                            }
                            flag = true;
                            return(flag);
                        }

                        default:
                        {
                            continue;
                        }
                        }
                    }
                }
                return(false);
            }
            return(flag);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Evalue two JValues to see whether left is bigger than right
 /// </summary>
 /// <param name="leftValue">left operand</param>
 /// <param name="rightValue">right operand</param>
 /// <returns>true if left is greater than right</returns>
 protected override bool EvaluateValues(JValue leftValue, JValue rightValue)
 {
     return(leftValue.CompareTo(rightValue) > 0);
 }