ValidationHandler.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. throw e.Exception;
  27. }
  28. else
  29. {
  30. handle(sender,e);
  31. }
  32. }
  33. /*
  34. public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException, object sender, string message, XmlSeverityType severity)
  35. {
  36. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  37. }
  38. public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)
  39. {
  40. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
  41. }
  42. public static void RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)
  43. {
  44. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);
  45. }
  46. public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
  47. {
  48. RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
  49. }
  50. public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)
  51. {
  52. RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);
  53. }
  54. */
  55. }
  56. }