/// <summary> /// Gets the common type to which both types can be promoted. /// </summary> /// <param name="leftType">First type.</param> /// <param name="rightType">Second type.</param> /// <returns> /// Common type to which both types can be promoted. Throws if unable to find a common type. /// </returns> public QueryScalarType GetCommonType(QueryScalarType leftType, QueryScalarType rightType) { Type commonClrType = LinqTypeSemantics.GetCommonType(((QueryClrPrimitiveType)leftType).ClrType, ((QueryClrPrimitiveType)rightType).ClrType); return(new QueryClrPrimitiveType(commonClrType, this)); }
/// <summary> /// Compares the primitive value to another value and returns their relative ordering. /// </summary> /// <param name="value">First value.</param> /// <param name="otherValue">Second value.</param> /// <returns> /// Integer which is less than zero if this value is less than the other value, 0 if they are equal, /// greater than zero if this value is greater than the other value /// </returns> public int Compare(QueryScalarValue value, QueryScalarValue otherValue) { var t1 = (QueryClrPrimitiveType)value.Type; var t2 = (QueryClrPrimitiveType)otherValue.Type; object v1 = value.Value; object v2 = otherValue.Value; if (this.IsSpatialType(t1)) { ExceptionUtilities.Assert(this.IsSpatialType(t2), "Because CLR types match, both values should both be spatial. Type was '{0}'", t2); ExceptionUtilities.CheckObjectNotNull(this.SpatialEqualityComparer, "Cannot compare spatial values without a spatial equality-comparer"); return(this.SpatialEqualityComparer.Equals(v1, v2) ? 0 : 2); } if (t1.ClrType != t2.ClrType) { Type commonClrType = LinqTypeSemantics.GetCommonType(t1.ClrType, t2.ClrType); commonClrType = Nullable.GetUnderlyingType(commonClrType) ?? commonClrType; if (v1 != null) { v1 = ArithmeticEvaluationHelper.ChangeType(v1, commonClrType); } if (v2 != null) { v2 = ArithmeticEvaluationHelper.ChangeType(v2, commonClrType); } } if (v1 == null) { if (v2 == null) { // both null - are equal return(0); } else { // first null, second not-null return(-1); } } else { if (v2 == null) { // first not null, second null return(1); } } var bytes1 = v1 as byte[]; if (bytes1 != null) { var bytes2 = (byte[])v2; return(CompareByteArrays(bytes1, bytes2)); } IComparable cv1 = (IComparable)v1; return(cv1.CompareTo(v2)); }