Problem in deriving class from XmlNode BCL class

  • Thread starter Mahesh Devjibhai Dhola
  • Start date
M

Mahesh Devjibhai Dhola

Hi All,
I want to make a custom class in c#, which extends System.Xml.XmlNode class
of BCL.

Now in custom class, I have implement abstract methods of XmlNode class
also. Now when I am trying to run the class it gives an error that
"System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level".

This error comes because XmlNode has not any public constructor. I found
XmlNode has two constructor but both are private or friend (i dont know
exactly).

I also found one MSDN article where it says that "Never derive any class
directly from XmlNode" but its just recommendation.
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/ht
ml/cpconextendingdom.asp)

Though, Microsoft has derived some of BCL classes from base XmlNode, so why
we can not derive?
System.Object
System.Xml.XmlNode
System.Xml.XmlAttribute
System.Xml.XmlDocument
System.Xml.XmlDocumentFragment
System.Xml.XmlEntity
System.Xml.XmlLinkedNode
System.Xml.XmlNotation

So i think there must be some way out of this....

So what to do to create a derived class from XmlNode?
I heard that many experts are giving their service in news groups. So please
help me out of this.

I have already derived few of my classes from XmlDocument, XmlElement,
XmlAttribute etc. So i dont want to derive from them but i want to derive
the class from XmlNode it self. Please help me to get the answer...

Thanks in Advance.

Thanking you,
Mahesh Devjibhai Dhola
"Empower yourself...."
 
D

Dennis Myrén

Unfortunately, you can not derive from System.Xml.XmlNode, because
the two constructors defined are both internal.

I would like to know in which context you are coming across to be needing to
derive
a class from XmlNode, and what is it that you are trying to achieve?
 
M

Mahesh Devjibhai Dhola

Hi Dennis,
Thanking you very much for your reply...
I thought the same thing that i will not be able to derive class from it.
Is there any document which says about its constructors? So i could know...

What is the intention of microsoft not to make it derivable? If Microsoft do
not want to make it derivable then it should declare that class as sealed or
final, not abstract? what is the design aspect behind that?

My real intention is to make my own xml assembly, which in fact is wrapper
of all the System.Xml classes with my own added functionalities in each
classes. I want all those classes but it should be mine not Microsoft. So i
am deriving those classes from System.Xml and making my own custom classes
with the changed class name, and added my own functioanlities in addition to
available facilities of extended class from System.Xml

Can you give me some way?

Thanks in advance....
 
D

Dennis Myrén

Mahesh,
Is there any document which says about its constructors? So i could know...
MSDN provides documentation on the .NET Framework SDK.
System.Xml.XmlNode documentation can be found here:
http://msdn.microsoft.com/library/d...pref/html/frlrfsystemxmlxmlnodeclasstopic.asp

Also, great software for viewing .NET assemblies is
Lutz Roeder's .NET Reflector.
You should download that. It is free and can be downloaded from here:
http://www.aisto.com/roeder/dotnet/
What is the intention of microsoft not to make it derivable? If Microsoft
do
not want to make it derivable then it should declare that class as sealed
or
final, not abstract? what is the design aspect behind that?
The reason it is inheritable(not sealed) is it works as a base class
for a number of classes in the system.xml.dll,
including XmlDocument and XmlElement(indirect via XmlLinkedNode).
I do not know though, why the constructurs are internal rather than
protected.
I guess they do now want anyone to derive XmlNode.
Can you give me some way?
Well, most of the core logic is provided by XmlElement i think.
Maybe you could write your own XmlNode and derive from XmlElement.

Otherwise, i am afraid i really do not have any good advice for you.
Other than, of course, create an actual wrapper not inherited from,
but rather utilizing XmlNode internally.
That will request a great deal of code though.
 
M

Mahesh Devjibhai Dhola

Thanks a lot Dennis,

1. I read already that MSDN documentation but there is nothing about
XmlNode's constructor. Though i found in dotnet247 site, in which they wrote
that it has 2 private constructor, but i dont believe that it will be
private.
http://www.dotnet247.com/247reference/System/Xml/XmlNode/__members
I will see it using the .Net Reflector you have mentioned.
Thanks for it.

2. I got your point about the reason not to make it sealed...inheritable

3. I will try using XmlElement. and i will see also Mono's source. I think
this is the last option...

Thanking you very much, Dennis for quick and exact answers....

Mahesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top