private TypeMath(Type valueType)
{
if (!TypeInfo.IsNumericType(valueType))
throw new Exception("Numeric type is required for math!");
Min = TypeMathExpressionHelper.GetMinDelegate<BinOp>(valueType, typeof(object));
Max = TypeMathExpressionHelper.GetMaxDelegate<BinOp>(valueType, typeof(object));
Sum = TypeMathExpressionHelper.GetSumDelegate<BinOp>(valueType, typeof(object));
Multiply = TypeMathExpressionHelper.GetMultiplyDelegate<BinOp>(valueType, typeof(object));
if (TypeInfo.IsNullableType(valueType))
{
var nc = new NullableConverter(valueType);
Zero = nc.ConvertFrom(Convert.ChangeType(0, Nullable.GetUnderlyingType(valueType)));
One = nc.ConvertFrom(Convert.ChangeType(1, Nullable.GetUnderlyingType(valueType)));
SumNullAsZero = TypeMathExpressionHelper.GetSumIsNullDelegate<BinOp>(valueType, typeof(object), Zero);
MultiplyNullAsOne = TypeMathExpressionHelper.GetMultiplyIsNullDelegate<BinOp>(valueType, typeof(object), One);
}
else
{
Zero = Convert.ChangeType(0, valueType);
One = Convert.ChangeType(1, valueType);
SumNullAsZero = Sum;
MultiplyNullAsOne = Multiply;
}
}