Reformatting the code according to castle guidelines.
[castle.git] / Components / General / Validator / Castle.Components.Validator / Validators / NonEmptyValidator.cs
blobe4e27825754320b3d6d64f56a17187ded440e2fd
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.Collections;
20 /// <summary>
21 /// Ensures that a property was
22 /// filled with some value
23 /// </summary>
24 [Serializable]
25 public class NonEmptyValidator : AbstractValidator
27 /// <summary>
28 /// Check that this property has a value that is not null or empty (if string)
29 /// </summary>
30 /// <param name="instance"></param>
31 /// <param name="fieldValue"></param>
32 /// <returns><c>true</c> if the field is OK</returns>
33 public override bool IsValid(object instance, object fieldValue)
35 return fieldValue != null && fieldValue.ToString().Length != 0;
38 /// <summary>
39 /// Gets a value indicating whether this validator supports web validation.
40 /// </summary>
41 /// <value>
42 /// <see langword="true"/> if web validation is supported; otherwise, <see langword="false"/>.
43 /// </value>
44 public override bool SupportsWebValidation
46 get { return true; }
49 /// <summary>
50 /// Applies the web validation by setting up one or
51 /// more input rules on <see cref="IWebValidationGenerator"/>.
52 /// </summary>
53 /// <param name="config">The config.</param>
54 /// <param name="inputType">Type of the input.</param>
55 /// <param name="generator">The generator.</param>
56 /// <param name="attributes">The attributes.</param>
57 /// <param name="target">The target.</param>
58 public override void ApplyWebValidation(WebValidationConfiguration config, InputElementType inputType,
59 IWebValidationGenerator generator, IDictionary attributes, string target)
61 base.ApplyWebValidation(config, inputType, generator, attributes, target);
63 generator.SetAsRequired(BuildErrorMessage());
66 /// <summary>
67 /// Returns the key used to internationalize error messages
68 /// </summary>
69 /// <value></value>
70 protected override string MessageKey
72 get { return MessageConstants.IsRequiredMessage; }