Say I have an interface WorksWithType<T>
and class MyClass
that implements both WorksWithType<TypeA>
and WorksWithType<TypeB>
.
If my interface looks like
public interface WorksWithType<T> {
void DoSomething(T foo);
void DoSomethingElse();
}
it is easy to implement two different DoSomething
method overloads in MyClass
.
public class MyClass : WorksWithType<TypeA>, WorksWithType<TypeB> {
{
public void DoSomething(TypeA fooA) { ... }
public void DoSomething(TypeB fooB) { ... }
...
}
However, there doesn't seem to be a way to implement overloads of DoSomethingElse
. In my mind I feel as though I should be able to change the signature on the interface to be
void DoSomethingElse<T>();
and then overload the class with
public void DoSomethingElse<TypeA>() { ... }
public void DoSomethingElse<TypeB>() { ... }
What is the correct approach here, if there is one?