I have a static method that validates some XML. In order to validate the XML and not stop on errors it needs to have a static callback ValidationEventHandler to handle error events (if you don’t register a callback, any errors throw an exception and validation stops).
So in this ValidationEventHandler is where you handle any validation errors. The static validation method reads the XML and for any error events, the event handler would be called.
My problem is, the static validation method needs to return a bool flag to indicate if there were any errors, and an output parameter string that has a list of errors. But since the error handling is done in the ValidationEventHandler, which had to be static because the validation method is static, how do I keep a running list of errors that occurred in the eventhandler?
If these weren’t static, I’d just make a instance variables to hold an error flag and an error string, but I have no idea how to pass data from a static event handler to a static method which does the processing that causes the event to occur for that handler.
Any ideas?
If I understand this correctly, you can do this a few different ways
The first way would be to create a static property:
The other option (and this depends on if you have access to the event code) is to create a custom
EventArgsclass