I dont know if what I’d like to do is simply not possible: or I’m not thinking about it in the correct way.
I’m trying to construct a repository interface class which accepts a generic type and uses this as the basis for the return on most of its methods, ie:
public interface IRepository<T> {
void Add(T source);
T Find(int id);
}
This would then be inherited by an actual repository class, like so:
public class TestClientRepository : IRepository<ClientEmailAddress>, IRepository<ClientAccount> {
}
The idea is that within a ClientRepository, for example, I will want to perform operations against a few different object types (ClientAccount, ClientEmailAddress etc); but in the main the types of operations needed are all the same.
When I try to use the TestClientRepository (after implementing the Interfaces explicitly) I cannot see the multiple Find and Add methods.
Can anyone help?
Thanks.
Sure – all you’ve got to do is use it as the appropriate interface:
Basically explicitly implemented interface methods can only be called on an expression of the interface type, not on the concrete type that implements the interface.