Today I encountered a small problem, and unfortunately I have not found a good solution. I would like to create a extension method for some generic interface. This method accepts a different type of a generic parameter, as seen below
public interface IGenericInterface<TSource>
{
void DoSomething<TDest>();
}
How to call a DoSomething2 method exactly in the same way as DoSomething method (without passing first type)?
public void DoSomething<TDest>()
//Called like below
testClass.DoSomething<object>();
instead of (like my current signature)
public static void DoSomething2<TDest, TSource>(this IGenericInterface<TSource> interf)
//called like below
testClass.DoSomething2<string, object>(); // have to repass object type
I know that the compiler can not automatically infer the second type (link). But I'm curious if anyone has found a solution.