Reformatting the code according to castle guidelines.
[castle.git] / Components / General / Validator / Castle.Components.Validator / Validators / CollectionNotEmptyValidator.cs
blobdb4e3af5a7d7ddcf807962af7627d2855c7300b2
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.Collections;
19 /// <summary>
20 /// Validates that the content is a collection that is not empty
21 /// </summary>
22 public class CollectionNotEmptyValidator : AbstractValidator
24 /// <summary>
25 /// Implementors should perform the actual validation upon
26 /// the property value
27 /// </summary>
28 /// <param name="instance">The target type instance</param>
29 /// <param name="fieldValue">The property/field value. It can be null.</param>
30 /// <returns>
31 /// <c>true</c> if the value is accepted (has passed the validation test)
32 /// </returns>
33 public override bool IsValid(object instance, object fieldValue)
35 ICollection collection = fieldValue as ICollection;
36 if (collection == null)
38 return false;
40 return collection.Count != 0;
43 /// <summary>
44 /// Gets a value indicating whether this validator supports web validation.
45 /// </summary>
46 /// <value>
47 /// <see langword="true"/> if web validation is supported; otherwise, <see langword="false"/>.
48 /// </value>
49 public override bool SupportsWebValidation
51 get { return false; }
54 protected override string MessageKey
56 get { return MessageConstants.CollectionNotEmpty; }