Beispiel #1
0
        public override bool Evaluate(object candidate)
        {
            candidate = AsAttributeValuesMapValue(candidate);

            if (candidate == null && TheObject == null)
            {
                return(true);
            }

            if (candidate == null || TheObject == null)
            {
                return(false);
            }

            var oid = candidate as OID;

            if (oid != null && !IsNative())
            {
                return(_oid != null && _oid.Equals(oid));
            }

            if (AttributeValueComparator.IsNumber(candidate) && AttributeValueComparator.IsNumber(TheObject))
            {
                return(AttributeValueComparator.Compare((IComparable)candidate, (IComparable)TheObject) == 0);
            }

            return(Equals(candidate, TheObject));
        }
 public virtual void Test1()
 {
     AssertEquals(0, AttributeValueComparator.Compare(10, Convert.ToSingle(10)));
     AssertEquals(0, AttributeValueComparator.Compare(10, Convert.ToInt64(10)));
     AssertEquals(0, AttributeValueComparator.Compare(10, Convert.ToDouble(10)));
     AssertEquals(0, AttributeValueComparator.Compare(10, (byte)10));
     AssertEquals(0, AttributeValueComparator.Compare(10, 10));
     AssertEquals(0, AttributeValueComparator.Compare(10, (short)10));
     AssertEquals(1, AttributeValueComparator.Compare(10, (short)9));
     AssertEquals(10.CompareTo(9), AttributeValueComparator.Compare(10, (short)9));
 }
Beispiel #3
0
        public override bool Evaluate(object candidate)
        {
            if (candidate == null && TheObject == null)
            {
                return(true);
            }

            candidate = AsAttributeValuesMapValue(candidate);

            if (candidate == null)
            {
                return(false);
            }

            if (!(candidate is IComparable))
            {
                throw new OdbRuntimeException(
                          NDatabaseError.QueryComparableCriteriaAppliedOnNonComparable.AddParameter(
                              candidate.GetType().FullName));
            }

            var comparable1 = (IComparable)candidate;
            var comparable2 = (IComparable)TheObject;

            switch (ComparisonType)
            {
            case ComparisonConstraint.ComparisonTypeGt:
            {
                return(AttributeValueComparator.Compare(comparable1, comparable2) > 0);
            }

            case ComparisonConstraint.ComparisonTypeGe:
            {
                return(AttributeValueComparator.Compare(comparable1, comparable2) >= 0);
            }

            case ComparisonConstraint.ComparisonTypeLt:
            {
                return(AttributeValueComparator.Compare(comparable1, comparable2) < 0);
            }

            case ComparisonConstraint.ComparisonTypeLe:
            {
                return(AttributeValueComparator.Compare(comparable1, comparable2) <= 0);
            }
            }

            throw new OdbRuntimeException(NDatabaseError.QueryUnknownOperator.AddParameter(ComparisonType));
        }