private void CoerceTypes(string operatorName, ref Expression leftExpr, ref Expression rightExpr) { if (leftExpr.Type != rightExpr.Type) { var leftType = TypeFns.GetNonNullableType(leftExpr.Type); var rightType = TypeFns.GetNonNullableType(rightExpr.Type); if (leftType == typeof(String)) { ConvertExpr(ref rightExpr, ref leftExpr); } else if (rightType == typeof(String)) { ConvertExpr(ref leftExpr, ref rightExpr); } else if ((TypeFns.IsNumericType(leftType) || TypeFns.IsEnumType(leftType)) && (TypeFns.IsNumericType(rightType) || TypeFns.IsEnumType(rightType))) { var leftIx = NumericTypes.IndexOf(leftType); var rightIx = NumericTypes.IndexOf(rightType); if (leftIx < rightIx) { ConvertExpr(ref leftExpr, ref rightExpr); } else { ConvertExpr(ref rightExpr, ref leftExpr); } } else if (leftType == typeof(Guid) || leftType == typeof(DateTime) || leftType == typeof(Boolean) || leftType == typeof(TimeSpan) || TypeFns.IsNumericType(leftType) || TypeFns.IsEnumType(leftType)) { ConvertExpr(ref rightExpr, ref leftExpr); } else { throw new Exception("Unable to perform operation: " + operatorName + "on types:" + leftExpr.Type + ", " + rightExpr.Type); } } }