Consider the following classes:
public class Vehicle { ... }
public class Coverage { ... }
public class VehicleList : IEnumerable<Vehicle> { ... }
public class CoverageList : IEnumerable<Coverage> { ... }
public abstract class Quote
{
protected VehicleList vehicles;
protected CoverageList coverages;
internal Quote() { ... }
public IReadOnlyCollection<Vehicle> Vehicles
{
get { return this.vehicles.AsReadOnly(); }
}
public IReadOnlyCollection<Coverage> Coverages
{
get { return this.coverages.AsReadOnly(); }
}
...
}
public sealed class OhQuote : Quote
{
//needs to access protected fields
...
}
public sealed class InQuote : Quote { ... }
public sealed class MiQuote : Quote { ... }
Quote
fully encapsulates the functionality of both VehicleList
and CoverageList
so I'd like to mark those classes as internal
. The problem is that they are the types of protected
fields of a public
class. If I mark those fields as protected internal
then they are protected
OR internal
. What I really need is for them to be protected
AND internal
(with protected
taking precedence within the assembly). You can see that neither Quote
(which has an internal
constructor) nor its subclasses (which are sealed
) can be extended outside the assembly. I've already figured out how to achieve the desired functionality using public interfaces but wanted to make sure there's not a more concise way.