I currently try to construct a generic interface that every (generic) class deriving it will have a method accepting a delegate that accepts the type parameter and returns another class of the same type, with only another type parameter.
I tried the following:
public interface GenericInterface<out T, out SomeDerived> where SomeDerived<T> : GenericInterface<T, SomeDerived> { SomeDerived<NT> bind<NT>(bindee<T, NT, SomeDerived<NT>> bindFunc); } public delegate AnotherDerived<T2> bindee<in T1, out T2, out AnotherDerived>(T1 param) where AnotherDerived<T2> : GenericInterface<T2, AnotherDerived>; public class Derived<T> : GenericInterface<T, Derived> { Derived<NT> bind<NT>(bindee<T, NT, Derived<NT>> bindFunc); } But it fails to compile and I get this error:
Invalid token '<' in class, struct, or interface member declaration
What is the correct design in such case?
EDIT:
I understand the syntatic reason for the compiler errors. You cannot apply a generic type argument a parameter in a where clause. I am asking what is the best way to mimic such behavior.