C# 您能否拥有一个内部接口,该接口仅由公共接口在内部使用

C# 您能否拥有一个内部接口,该接口仅由公共接口在内部使用,c#,inheritance,interface,accessor,C#,Inheritance,Interface,Accessor,我想做一些类似的事情: internal interface IInternalStore { object GetValue(object key); } public interface IStore<in TKey, TValue> : IInternalStore { TValue GetValue(TKey key); } public interface IStore : IInternalStore { TValue GetV

我想做一些类似的事情:

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);
}
内部接口IInternalStore
{
对象GetValue(对象键);
}
公共接口晶体管
:IInternalStore
{
TValue GetValue(TKey);
}
公共接口晶体管
:IInternalStore
{
TValue GetValue(TKey);
}
我想这样做的原因是,我可以检查类是否是IInternalStore,而不必检查单个接口类型

//由实现开发人员定义
公共级MyStoreA
:晶体管
{
int GetValue(int键);
}
公共类MyStoreB
:晶体管
{
TValue GetValue(TKey);
}
//我使用的内部方法
void GetValueFromStore(对象存储)
{
如果(存储为IInternalStore)
{
{做点什么}
}
}
但是从我所看到的,我想做的是不可能的,因为IInternalStore必须与继承的接口具有相同的访问器,并且它需要开发人员实现所有继承的方法

我错了吗?有没有办法做到我想要的

我错了吗?有没有办法做到我想要的

不,你是对的-公共接口不能扩展内部接口

我建议您将这两个接口分开。如果需要,您可以始终拥有一个扩展这两个类的内部接口,或者让相关类实现这两个类

// 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}
    }
}