I want to write something like the following:
internal class InternalData { } public class PublicData { } abstract internal class Base { internal Base() { } private static InternalData CreateInternalDataFromPublicData(PublicData publicData) { throw new NotImplementedException(); } abstract protected void DoProcess(InternalData internalData); public void Process(PublicData publicData) { InternalData internalData = CreateInternalDataFromPublicData(publicData); DoProcess(internalData); } } public sealed class Derived : Base { protected override void DoProcess(InternalData internalData) { throw new NotImplementedException(); } }
That is, Base
contains some internal logic and is not inherited by classes outside my assembly; and Derived
is available outside. InternalData
also contains some internal logic, and since it (and should) will never be used externally, I also want to make it internal.
Of course, the code above will not compile, since Base
should not be less accessible than Derived
. I can set Base
as public
, this is fine, but this leads to another problem. If Base
is publicly available, some other builds may have multiple ExternalDerived : Base
. But Base.DoProcess
takes an InternalData
as an argument, so ExternalDerived
cannot implement it (because it does not know about InternalData
). Base
internal, cost-free constructor prevents the creation of any ExternalDerived
instances, and therefore no one will implement ExternalDerived.DoProcess
and there is no InternalData
, but the compiler does not know this.
How can I rewrite the above code so that the DoProcess(InternalData)
abstract method DoProcess(InternalData)
and the InternalData
class is internal?
source share