Mam dwa niepowiązane ze sobą interejsy
public interface A
{
void MyMethod(string arg1);
}
public interface B
{
void MyMethod(string arg1);
}
Chcę teraz stworzyć metodę genereczna która wywoła odpowiednią metodę z interfejsu A albo B.
public void CallMyMethod<T>(T myObject, string arg) where T : A,B
{
myObject.MyMethod(arg);
}
Problem polega na tym że kompilator nie wie, czy chodzi o interejs A czy B. Czy jest sposób by to zrobić generycznie czy muszę dwie oddzielne metody stworzyć?
Błąd kompilatora:
The call is ambigous between the following methods or properties: 'A.MyMethod(string)' and 'B.MyMethod(string)'