2016-08-16 52 views
2

我有類ImplementationDetail我想保持內部,如:如何使用較少可訪問的參數派生公共泛型類而不存在不一致的可訪問性錯誤?

internal class ImplementationDetail 
{ 
} 

我有GenericBaseClass是私人使用它的參數,如:

public class GenericBaseClass<T> 
{ 
    private T useImplementationDetail; 
} 

而且,我有一個Derived類指定使用ImplementationDetail,例如:

public class DerivedClass: GenericBaseClass<ImplementationDetail> 
{ 
} 

這會導致錯誤CS0060 Inconsistent accessibility;這是由ImplementationDetailinternal造成的,而DerivedClasspublic。 如何避免CS0060編譯器錯誤,同時保持ImplementationDetailinternal

+0

公開'ImplementationDetail'!當你將這個類暴露在它所在的單元之外時,你無法做其他任何事情。 – DavidG

+0

使'ImplementationDetail'成爲一個接口,並使接口公開。如果你有一個公共類'T',那'T'應該和類一樣容易訪問。 – Jonesopolis

+0

不,讓它保護,只有派生類可以訪問。 – Botonomous

回答

0

這是不可能的。

你必須使用公共接口或類。請參閱@DavidG,@Jonesopolis的評論。

1

而不是使用內部類,使用接口。然後在想要保密的方法上使用explicit implementation。那樣,他們從不暴露。

+0

當客戶端通過定義這些方法的接口使用實例時,不顯式實現嗎? –