private IComparable PerformArithmeticOperation(IEvaluable evaluable, IJSONDocument document, ArithmeticOperation operation) { IJsonValue value1, value2; if (!Evaluate(out value1, document)) { return(null); } if (!evaluable.Evaluate(out value2, document)) { return(null); } TypeCode actualType1, actualType2; FieldDataType fieldDataType1 = JSONType.GetJSONType(value1.Value, out actualType1); FieldDataType fieldDataType2 = JSONType.GetJSONType(value2.Value, out actualType2); if (fieldDataType1.CompareTo(fieldDataType2) != 0) { return(null); } return(Evaluator.PerformArithmeticOperation(value1, actualType1, value2, actualType2, operation, fieldDataType1)); }
public override int CompareTo(object obj) { var value = obj as AttributeValue; if (value != null) { switch (value.Type) { case AttributeValueType.All: return(0); case AttributeValueType.Single: case AttributeValueType.Mask: case AttributeValueType.Multiple: case AttributeValueType.Null: case AttributeValueType.None: return(type.CompareTo(value.DataType)); default: throw new IndexException(ErrorCodes.Indexes.ATTRIBUTEVALUE_TYPE_MISMATCH, new[] { this.ValueInString, value.ValueInString }); } } throw new IndexException(ErrorCodes.Indexes.ATTRIBUTEVALUE_TYPE_MISMATCH, new[] { this.ValueInString, value.ToString() }); }
public static int Compare(IComparable first, FieldDataType firstType, TypeCode firstActualType, object second, FieldDataType secondType, TypeCode secondActualType, SortOrder order) { int typeRule = firstType.CompareTo(secondType); if (typeRule != 0) { return(typeRule); } switch (firstType) { case FieldDataType.Number: return(order == SortOrder.ASC ? CompareNumbers(first, firstActualType, second, secondActualType) : 0 - CompareNumbers(first, firstActualType, second, secondActualType)); case FieldDataType.Null: return(0); default: return(order == SortOrder.ASC ? first.CompareTo(second) : 0 - first.CompareTo(second)); } }