ValidationHandler.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. internal 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 RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)
  31. {
  32. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);
  33. }
  34. public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
  35. {
  36. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
  37. }
  38. public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)
  39. {
  40. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);
  41. }
  42. }
  43. }