Is it possible to inherit protected System classes

  • Thread starter Thread starter Brian Taylor
  • Start date Start date
B

Brian Taylor

Is it possible to inherit protected system classes to create new
functionality?

Examples include:
1. CurrencyManager
2. DataBindingsCollection
3. DataTableCollection
4. And more...

If I try and override these classes I get the following error:
<class> is inaccessible due to its protection level.

The main reason for inheriting these classes is to create new functionality.
For example, fix problems with data binding, or create new data sets and
tables without the need for casting.

Do I have any hope with this ...?

BT

Here is some code:
public class cm : System.Windows.Forms.CurrencyManager

{

protected internal cm(string s) : base (s)

{

}

}

public class x : System.Xml.XmlElement

{

public x() : base()

{

}

}
 
Download a copy of Lutz Roeder's Reflector; it'll help you immensely with
questions like this.
http://www.aisto.com/roeder/dotnet/

CurrencyManager's constructor is internal (which the docs won't tell you --
hence the plug for Reflector), so you can't call the constructor from a
different assembly. And a derived class's constructor must call its parent
class's constructor (at least in C#); if you can't do that, you can't derive
the class. So it looks like no, you can't descend from CurrencyManager,
since the internal constructor isn't visible from your assembly. (You might
be able to do this in straight IL -- I think I read somewhere that it's up
to the compiler to respect visibility specifiers like "internal", and that
ilasm.exe doesn't do those checks -- but I can't help with the exact
mechanics.) The same thing is true of DataTableCollection: internal
constructor.

I can't find a class called DataBindingsCollection. There is a
DataBindingCollection, but it's in System.Web.Forms. And it's sealed, so
you would get a different error if you tried to descend from it.
 
Back
Top