Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Components / Validator / Castle.Components.Validator / Attributes / ValidateLengthAttribute.cs
blob79e41a812c2a0a2f04a13d581d2ea719eef04c74
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;
19 /// <summary>
20 /// Validate that this property has the required length (either exact or in a range)
21 /// </summary>
22 [Serializable, CLSCompliant(false)]
23 public class ValidateLengthAttribute : AbstractValidationAttribute
25 private readonly IValidator validator;
27 /// <summary>
28 /// Initializes a new exact length validator.
29 /// </summary>
30 /// <param name="exactLength">The exact length required.</param>
31 public ValidateLengthAttribute(int exactLength)
33 validator = new LengthValidator(exactLength);
36 /// <summary>
37 /// Initializes a new exact length validator.
38 /// </summary>
39 /// <param name="exactLength">The exact length required.</param>
40 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
41 public ValidateLengthAttribute(int exactLength, String errorMessage) : base(errorMessage)
43 validator = new LengthValidator(exactLength);
46 /// <summary>
47 /// Initializes a new range based length validator.
48 /// </summary>
49 /// <param name="minLength">The minimum length, or <c>int.MinValue</c> if this should not be tested.</param>
50 /// <param name="maxLength">The maximum length, or <c>int.MaxValue</c> if this should not be tested.</param>
51 public ValidateLengthAttribute(int minLength, int maxLength)
53 validator = new LengthValidator(minLength, maxLength);
56 /// <summary>
57 /// Initializes a new range based length validator.
58 /// </summary>
59 /// <param name="minLength">The minimum length, or <c>int.MinValue</c> if this should not be tested.</param>
60 /// <param name="maxLength">The maximum length, or <c>int.MaxValue</c> if this should not be tested.</param>
61 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
62 public ValidateLengthAttribute(int minLength, int maxLength, String errorMessage) : base(errorMessage)
64 validator = new LengthValidator(minLength, maxLength);
67 /// <summary>
68 /// Constructs and configures an <see cref="IValidator"/>
69 /// instance based on the properties set on the attribute instance.
70 /// </summary>
71 /// <returns></returns>
72 public override IValidator Build()
74 ConfigureValidatorMessage(validator);
76 return validator;