Kasper van den Berg
Kasper van den Berg

Reputation: 9526

How to derive public generic class using less accessible parameter without inconsistent accessibility error?

I have the class ImplementationDetail which I would like to keep internal, e.g.:

internal class ImplementationDetail
{
}

I have GenericBaseClass that uses its parameter privately, e.g.:

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

And, I have a Derived class that specifies to use ImplementationDetail, e.g.:

public class DerivedClass: GenericBaseClass<ImplementationDetail>
{
}

This results in the error CS0060 Inconsistent accessibility; which is caused by ImplementationDetail being internal whereas DerivedClass is public. How can I avoid the CS0060 compiler error while keeping ImplementationDetail internal?

Upvotes: 2

Views: 142

Answers (2)

Kasper van den Berg
Kasper van den Berg

Reputation: 9526

It is not possible.

You have to use a public interface or class. See the comments of @DavidG, @Jonesopolis.

Upvotes: 0

Xavier J
Xavier J

Reputation: 4668

Instead of using an internal class, use an interface. Then use explicit implementation on the methods you want to keep private. That way, they're never exposed.

Upvotes: 1

Related Questions