Consider two generic classes
class Result<T1, T2> {}
class Value<T> {}
Is there some way of overloading the + operator that would allow me to write the following in such a way that the types are properly captured in the result, i.e. r has the type Result<int,string>?
Value<int> a;
Value<string> b;
var r = a + b;
I can write this:
class Value<T> {
public static Result<T,T> operator+(Value<T> a, Value<T> b) { ... }
}
Which will work for any pair of Value<T>'s, such as two Value<int>'s, but what about when the types differ?
Looking at previous questions about C# operator overloading, none of them seem to answer this specific question. This one is perhaps the closest: Overloading operator for generics C#
The motivation behind trying to do this is that if the Result<T1, T2> class has a method that takes a delegate as an argument, knowing the specific types T1 and T2 at compile time makes it possible to omit types from the lambda expression when calling that method.
+to be defined forValue<T>andValue<U>for any two typesTandU?