Re: Constructor Accessibility - protected ctor inside public class with internal parameter
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Wed, 27 Aug 2008 12:29:49 -0700 (PDT)
On Aug 27, 10:15 pm, "jehugalea...@xxxxxxxxx" <jehugalea...@xxxxxxxxx>
wrote:
Hello:
I have a public abstract class. The concrete subclasses must pass an
instance of an internal class to the abstract class' ctor.
I like to make the constructors of my abstract classes protected.
However, since it has a parameter that is of an internal type, I am
forced to make it internal also. This is fine since no one outside my
library can see it.
However, I would prefer to restrict this even more, so that only
subclasses can see the ctor.
"protected internal" provides the relationship:
visible to code within the library OR ANY subclasses.
I want:
visible to code within the library AND internal subclasses.
I suppose there is no solution. I was hoping someone could give me
some insight, however.
There is no way to do it in C#, even though the CLR does have the
specifier that you want (it's called FamilyAndAssembly, while
"protected internal" is FamilyOrAssembly), so it is possible to do
that by coding the class directly in IL (or ildasm'ing the .dll
generated from .cs, changing the visibility, and recompiling it). Of
course, it's too inconvenient for any normal development.
The only high-level .NET language I am aware of that exposes
FamilyAndAssembly visibility is RemObjects Oxygene - it has both
"assembly or protected" and "assembly and protected" visibility
specifiers.
.
- Prev by Date: Re: Initializing object arrays.
- Next by Date: Error in WPF application
- Previous by thread: Close() timeout in NetworkStream and Socket?
- Next by thread: Error in WPF application
- Index(es):
Relevant Pages
|