1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Runtime
.Serialization
;
21 /// This exception is raised when a validation error occurs
24 public class ValidationException
: ApplicationException
26 private String
[] validationErrorMessages
;
29 /// Initializes a new instance of the <see cref="ValidationException"/> class.
31 /// <param name="message">The message.</param>
32 public ValidationException(String message
) : base(message
)
37 /// Initializes a new instance of the <see cref="ValidationException"/> class.
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
)
46 /// Initializes a new instance of the <see cref="ValidationException"/> class.
48 /// <param name="message">The message.</param>
49 /// <param name="errorMessages">The error messages.</param>
50 public ValidationException(String message
, String
[] errorMessages
)
53 validationErrorMessages
= errorMessages
;
57 /// Initializes a new instance of the <see cref="ValidationException"/> class.
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
71 /// Initializes a new instance of the <see cref="ValidationException"/> class.
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
[]));
83 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with information about the exception.
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
);
98 /// Returns a list of current validation errors messages, if available.
100 public String
[] ValidationErrorMessages
104 if (validationErrorMessages
== null)
106 validationErrorMessages
= new String
[0];
108 return validationErrorMessages
;