Im wanting to do something along the lines of this:
internal interface IInternalStore
{
object GetValue(object key);
}
public interface IStore<in TKey, TValue>
: IInternalStore
{
TValue GetValue(TKey key);
}
public interface IStore
: IInternalStore
{
TValue GetValue<in TKey, TValue>(TKey key);
}
The reason i want to do this is so that i can check that the class is an IInternalStore without having to check for the individual interface types.
IE.
// Defined by the implementing developer
public class MyStoreA
: IStore<int, int>
{
int GetValue(int key);
}
public class MyStoreB<TKey, TValue>
: IStore
{
TValue GetValue(TKey key);
}
// Internal method used by me
void GetValueFromStore(object store)
{
if (store is IInternalStore)
{
{do something}
}
}
but from what I can see, what i want to do is not possible as the IInternalStore must be of the same accessor as the inherited interfaces and it would require the developer to implement all the inherited methods.
Am i wrong? Is there a way to do what im wanting?
No, you’re right – a public interface can’t extend an internal one.
I suggest you just separate the two interfaces. You can always then have an internal interface which extends both, if you want, or just make the relevant classes implement both classes.