Given the following generic interface and implementing class:
public interface IRepository<T> { // U has to be of type T of a subtype of T IQueryable<U> Find<U>() where U : T; } public class PersonRepository : IRepository<Employee> { }
How could I call the Find method without specififying U?
var repository = new EmployeeRepository(); // Can't be done IQueryable<Employee> people = repository.Find(); // Has to be, but isn't Employee a given in this context? IQueryable<Employee> people = repository.Find<Employee>(); // Here I'm being specific IQueryable<Manager> managers = repository.Find<Manager>();
In other words, what can be done to get type inference?
Thanks!
How about writing
It’s saving the same amount of typing but in a different way.