tags:

views:

34

answers:

1

I Want to raise an event to prevent any modification on the Xml file.

Simply raising an event is enough ? like

XElement doc = XElement.Load(@"d:\XMLFiles\namespace.xml");
doc.Changed +=new EventHandler<XObjectChangeEventArgs>(doc_Changed);

What is the code do i need to write inside doc_changed(..,...) to rollback any modifications?

    static void doc_Changed(object sender, XObjectChangeEventArgs e)
    {

        //what is the code needed here..?  

    }
+2  A: 

Rather than subscribing to Changed, you should subscribe to Changing so that you get notified before it happens.

The easiest way to prevent the change is to throw an exception... but that's quite a severe way of handling it. What situation are you really trying to prevent? Accidental changes due to a developer not understanding that this document is meant to be read-only?

Jon Skeet
yes Jon,you are exactly right.
guru
Now you have written Functional programming ,right?
guru
Not really sure what you mean... are you referring to the Real World Functional Programming book? If so, I only helped out a little - Tomas Petricek did the vast bulk of the work.
Jon Skeet
yes i was talking about the book.
guru