ValidationHandler.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. namespace System.Xml.Schema
  3. {
  4. /// <summary>
  5. /// </summary>
  6. public delegate void ValidationEventHandler(object sender,ValidationEventArgs e);
  7. /// <summary>
  8. /// Docs say we need to raise an exception if ValidationEventHandler is not set(null)
  9. /// So we use this class to raise the events rather than calling the delegate by itself
  10. /// </summary>
  11. public class ValidationHandler
  12. {
  13. public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException, object sender, string message, XmlSeverityType severity)
  14. {
  15. XmlSchemaException ex = new XmlSchemaException(message,innerException);
  16. ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);
  17. if(handle == null)
  18. {
  19. throw e.Exception;
  20. }
  21. else
  22. {
  23. handle(sender,e);
  24. }
  25. }
  26. public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)
  27. {
  28. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  29. }
  30. public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
  31. {
  32. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
  33. }
  34. }
  35. }