コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }