Fixing an issue where setting a custom property on a handler will not propagate it...
[castle.git] / Components / General / Validator / Castle.Components.Validator / Validators / NotSameValueValidator.cs
blob33a8bbd699e0a8d942f3548867538f51d070ebb7
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 /// <summary>
18 /// Validates that the content is not set to the specified value
19 /// </summary>
20 public class NotSameValueValidator : AbstractValidator
22 private readonly object value;
24 /// <summary>
25 /// Initializes a new instance of the <see cref="SameAsValidator"/> class.
26 /// </summary>
27 public NotSameValueValidator(object value)
29 this.value = value;
32 /// <summary>
33 /// Validates that the <c>fieldValue</c>
34 /// is not set to the specified value
35 /// </summary>
36 /// <param name="instance">The target type instance</param>
37 /// <param name="fieldValue">The property/field value. It can be null.</param>
38 /// <returns>
39 /// <c>true</c> if the value is accepted (has passed the validation test)
40 /// </returns>
41 public override bool IsValid(object instance, object fieldValue)
43 return Equals(value, fieldValue) == false;
46 /// <summary>
47 /// Gets a value indicating whether this validator supports browser validation.
48 /// </summary>
49 /// <value>
50 /// <see langword="true"/> if browser validation is supported; otherwise, <see langword="false"/>.
51 /// </value>
52 public override bool SupportsBrowserValidation
54 get { return false; }
57 /// <summary>
58 /// Returns the key used to internationalize error messages
59 /// </summary>
60 /// <value></value>
61 protected override string MessageKey
63 get { return MessageConstants.NotSameAsMessage; }
66 /// <summary>
67 /// Builds the error message.
68 /// </summary>
69 /// <returns></returns>
70 protected override string BuildErrorMessage()
72 return string.Format(GetString(MessageConstants.NotSameAsMessage), value);