ValidationHandler.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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,
  14. Exception innerException,
  15. string message,
  16. XmlSchemaObject xsobj,
  17. object sender,
  18. string sourceUri,
  19. XmlSeverityType severity)
  20. {
  21. XmlSchemaException ex = new XmlSchemaException (
  22. message, sender, sourceUri, xsobj, innerException);
  23. ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);
  24. if(handle == null)
  25. {
  26. if (e.Severity == XmlSeverityType.Error)
  27. throw e.Exception;
  28. }
  29. else
  30. {
  31. handle(sender,e);
  32. }
  33. }
  34. /*
  35. public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException, object sender, string message, XmlSeverityType severity)
  36. {
  37. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  38. }
  39. public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)
  40. {
  41. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  42. }
  43. public static void RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)
  44. {
  45. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);
  46. }
  47. public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
  48. {
  49. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
  50. }
  51. public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)
  52. {
  53. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);
  54. }
  55. */
  56. }
  57. }