views:

34

answers:

3

I can’t figure out why Control.CreateChildControls is visible in web page’s code-behind class. Namely, Control.CreateChildControls is defined as protected internal, which means that method is visible only to derived classes located inside the same assembly as Control class. So how is that possible since as as far as I know, web-page class is not compiled into same assembly as Control class ( System.Web.dll )?

thanx

+2  A: 

Unfortunately, the wording of 'protected internal' is misleading. It means 'protected' or 'internal' and not 'protected' and 'internal'.

In your %program files%\microsoft visual studio 9.0\vc#\Specifications\1033, you have the C# reference manual, this is at section 1.6.2.

Therefore a derived class can use it.

Timores
thank you both for your help
AspOnMyNet
+1  A: 

The Page class inherits from Control, which are both in the System.Web.UI namespace, and both in the System.Web assembly.

womp
+2  A: 

I find it very unhelpful to characterize the difference as between "protected and internal" vs "protected or internal". Which is "protected internal"?

You could say "protected internal is the least restrictive combination of protected and internal, therefore it means 'protected and internal'".

You could also say "protected internal restricts access to derived members or assembly members, therefore it means 'protected or internal'".

Yuck.

The better way to think about it is:

  • the default accessibility of a member is "private" -- the smallest possible accessibility domain
  • a modifier enlarges the accessibility domain of a member
  • therefore protected internal enlarges the accessibility domain twice, once to derived members, and once to assembly members.

For more thoughts on this see:

http://blogs.msdn.com/ericlippert/archive/2008/04/24/why-can-t-i-access-a-protected-member-from-a-derived-class-part-three.aspx

Eric Lippert