Fixing an issue where setting a custom property on a handler will not propagate it...
[castle.git] / Components / General / Validator / Castle.Components.Validator / ValidationException.cs
blobec9ad3670411ebe72a45850a74675309e96cdd55
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Components.Validator
17 using System;
18 using System.Runtime.Serialization;
20 /// <summary>
21 /// This exception is raised when a validation error occurs
22 /// </summary>
23 [Serializable]
24 public class ValidationException : ApplicationException
26 private String[] validationErrorMessages;
28 /// <summary>
29 /// Initializes a new instance of the <see cref="ValidationException"/> class.
30 /// </summary>
31 /// <param name="message">The message.</param>
32 public ValidationException(String message) : base(message)
36 /// <summary>
37 /// Initializes a new instance of the <see cref="ValidationException"/> class.
38 /// </summary>
39 /// <param name="message">The message.</param>
40 /// <param name="innerException">The inner exception.</param>
41 public ValidationException(String message, Exception innerException) : base(message, innerException)
45 /// <summary>
46 /// Initializes a new instance of the <see cref="ValidationException"/> class.
47 /// </summary>
48 /// <param name="message">The message.</param>
49 /// <param name="errorMessages">The error messages.</param>
50 public ValidationException(String message, String[] errorMessages)
51 : base(message)
53 validationErrorMessages = errorMessages;
56 /// <summary>
57 /// Initializes a new instance of the <see cref="ValidationException"/> class.
58 /// </summary>
59 /// <param name="message">The message.</param>
60 /// <param name="innerException">The inner exception.</param>
61 /// <param name="errorMessages">The error messages.</param>
62 public ValidationException(String message, Exception innerException, String[] errorMessages)
63 : base(message, innerException)
65 validationErrorMessages = errorMessages;
68 #region Serialization Support
70 /// <summary>
71 /// Initializes a new instance of the <see cref="ValidationException"/> class.
72 /// </summary>
73 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> that holds the serialized object data about the exception being thrown.</param>
74 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"></see> that contains contextual information about the source or destination.</param>
75 /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult"></see> is zero (0). </exception>
76 /// <exception cref="T:System.ArgumentNullException">The info parameter is null. </exception>
77 public ValidationException(SerializationInfo info, StreamingContext context) : base(info, context)
79 validationErrorMessages = (String[]) info.GetValue("validationErrorMessages", typeof(String[]));
82 /// <summary>
83 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with information about the exception.
84 /// </summary>
85 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> that holds the serialized object data about the exception being thrown.</param>
86 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"></see> that contains contextual information about the source or destination.</param>
87 /// <exception cref="T:System.ArgumentNullException">The info parameter is a null reference (Nothing in Visual Basic). </exception>
88 /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/></PermissionSet>
89 public override void GetObjectData(SerializationInfo info, StreamingContext context)
91 info.AddValue("validationErrorMessages", validationErrorMessages);
92 base.GetObjectData(info, context);
95 #endregion
97 /// <summary>
98 /// Returns a list of current validation errors messages, if available.
99 /// </summary>
100 public String[] ValidationErrorMessages
104 if (validationErrorMessages == null)
106 validationErrorMessages = new String[0];
108 return validationErrorMessages;