Thursday, February 08, 2007

Protected Internal??

So I was writing some code today that I thought was great! I went to show my Buddy and he pointed one thing out to me. I had a few methods in a base class marked as protected internal. He told me "I don't think that's doing what you think it's doing". I was thinking that these methods would only be accessible to inherited members AND members within the same assembly. I guess I just made the assumption since public static marks the member as both available to all AND a non instance member.

Anyways I decided to take a look at the good old msdn site to see exactly what it says. Basically this says it all "only derived types or types within the same assembly can access that member". Notice the keyword "OR" in there. So my members were either available to inherited members OR members within the same assembly....

But this is not what I wanted.. I wanted what it sounded like! a member that was available ONLY to inherited AND same assembly members! So the quick solution to this was to just mark my class as Internal and it's members Protected.


internal class SameAssemblyClass {
protected void InheritedMethod() { }

No comments: