How to add generic method to a class, that takes a class extending a generic class, ignoring it's parent template parameter?

Viewed 78

I have a class with such definition:

public abstract class BaseRepository<TEntity> where TEntity : class
{
   ...
}

Now, I have a bunch of classes extending BaseRepository. I want to create a method, that takes a child of BaseRepository as a generic parameter. And it works perfectly fine:

public void Method<T, TEntity> () where T : BaseRepository<TEntity> where TEntity : class
{
   ...
}

But I don't really care what TEntity is, I just care that it's a child of BaseRepository. I only use T in Method, therefore I would like to get rid of TEntity. A perfect usage of my Method would be:

instance.Method<CarsRepository>();

Does C# offer some syntax that would allow me to ommit TEntity as a generic argument? If not, what should I do, assuming I can't change BaseRepository syntax?

0 Answers
Related