is there some 'where' type contraints in can add to make the follwing code compile ?
public class Plus<T> : BinaryOperator<T> where T : ...
{
public override T Evaluate(IContext<T> context)
{
return left.Evaluate(context) + right.Evaluate(context);
}
}
Thanks :)
There are no such devices in C#. A few options are available, though:
dynamic
, which supports +
but offers no compile time checkingOperator
class which makes operators available as methods - again, without any compile-time checkingSo either:
return (dynamic)left.Evaluate(context) + (dynamic)right.Evaluate(context);
or
return Operator.Add(left.Evaluate(context), right.Evaluate(context));