Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ValidationHandler.cs « System.Xml.Schema « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 898a10a840f7d6588be547584c49b345a433cfcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;

namespace System.Xml.Schema
{
	/// <summary>
	/// </summary>
	public delegate void ValidationEventHandler(object sender,ValidationEventArgs e);

	/// <summary>
	/// Docs say we need to raise an exception if ValidationEventHandler is not set(null)
	/// So we use this class to raise the events rather than calling the delegate by itself
	/// </summary>
	internal class ValidationHandler
	{
		public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException,  object sender, string message, XmlSeverityType severity)
		{
			XmlSchemaException ex = new XmlSchemaException(message,innerException);
			ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);
			if(handle == null)
			{
				throw e.Exception;
			}
			else
			{
				handle(sender,e);
			}
		}
		public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)
		{
			RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);
		}
		
		public static void RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)
		{
			RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);
		}

		public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)
		{
			RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);
		}

		public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)
		{
			RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);
		}
	}
}