I am trying to pass multiple generic interfaces as parameters to the constructor of one of my classes.
The following code does not compile:
public interface IPosterGenerator<T>
{
IQueryable<T> GetPosters();
}
public class Pinboard
{
public Pinboard(IPosterGenerator<A> firstPosterGenerator, IPosterGenerator<B> secondPosterGenerator, IPosterGenerator<B> thirdPosterGenerator)
{
}
}
I have about a hundred different types of poster generators. They all inherit from the IPosterGenerator interface. When I instantiate a new Pinboard, I need to pass three IPosterGenerators to the pinboard’s constructor. However, every of these three IPosterGenerators will be of a different type. That’s why I came up with this silly A, B and C.
Can this be done at all?
It sounds like you probably want to make
Pinboardgeneric:To make it easier to call, you can also create a non-generic class with a generic method:
Then if you’ve already got the generators, you can just call: