private static Expression GetNumericValueValidityCheck(Expression sourceValue, Type targetType) { var nonNullableTargetType = targetType.GetNonNullableType(); var numericValueIsInRange = NumericValueIsInRangeComparison.For(sourceValue, nonNullableTargetType); if (NonWholeNumberCheckIsNotRequired(sourceValue, nonNullableTargetType)) { return(numericValueIsInRange); } var moduloOneEqualsZero = NumericConversions.GetModuloOneIsZeroCheck(sourceValue); return(Expression.AndAlso(numericValueIsInRange, moduloOneEqualsZero)); }
private static Expression GetNumericValueValidityCheck(Expression sourceValue, Type targetType) { var nonNullableTargetType = targetType.GetNonNullableType(); var numericValueIsInRange = NumericValueIsInRangeComparison.For(sourceValue, nonNullableTargetType); if (NonWholeNumberCheckIsNotRequired(sourceValue, nonNullableTargetType)) { return(numericValueIsInRange); } var one = GetConstantValue(1, sourceValue); var sourceValueModuloOne = Expression.Modulo(sourceValue, one); var zero = GetConstantValue(0, sourceValue); var moduloOneEqualsZero = Expression.Equal(sourceValueModuloOne, zero); return(Expression.AndAlso(numericValueIsInRange, moduloOneEqualsZero)); }