L
Lee
I'd like to implement a generic class that takes as its Type-parameter
a numeric type (e.g. (U)Int16/32/64, float, double, decimal, etc.).
The problem is that, having validated the Type-parameter, I cannot do
any arithmetic operations (+, -, *, /) on variables of that type.
I tried creating wrapper-classes for the numeric types I will support
and tried to derive them from a custom interface that specified the
above 4 operators -- but interfaces are not allowed to specify
operators.
The only solution I can think of is to use a 'switch' statement at the
places I need to do the arithmetic operations -- but to me that is a
very poor solution.
I'm fairly sure this problem has arisen before and I'm hoping someone
can point me to a viable solution.
a numeric type (e.g. (U)Int16/32/64, float, double, decimal, etc.).
The problem is that, having validated the Type-parameter, I cannot do
any arithmetic operations (+, -, *, /) on variables of that type.
I tried creating wrapper-classes for the numeric types I will support
and tried to derive them from a custom interface that specified the
above 4 operators -- but interfaces are not allowed to specify
operators.
The only solution I can think of is to use a 'switch' statement at the
places I need to do the arithmetic operations -- but to me that is a
very poor solution.
I'm fairly sure this problem has arisen before and I'm hoping someone
can point me to a viable solution.