Overriding events in an inherited class

R

Robert

Hi,

I've inherited the XmlDocument class to include some custom methods that I
want to use on a particular XML file.

I need to know whether the document has changed since being loaded, and I
wanted to be clever and hook up to the events that are already defined in
the XmlDocument class (i.e. NodeChanged, NodeInserted).

I had presumed I would simply be able to override them, however I cannot
seem to either find the syntax for this, or any exact resolution to this
question.

My current solution is to attach custom handlers to the base classes
events....

this.NodeChanged += new XmlNodeChangedEventHandler(MyNodeChangedEvent);

internal void MyNodeChangedEvent(Object src, XmlNodeChangedEventArgs args)
{
this.IsDirty = true;
}

Any help gratefully appreciated.

Robert
 
P

Peter Rilling

You can hook events by overriding the On... methods in the class and
providing your own logic. If you do this, it is important that you call the
On... method of the parent class so that the events will be fired after the
methods have been called.
 

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