Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Components / Validator / Castle.Components.Validator / Attributes / ValidateSetAttribute.cs
blobc21943c6adffa34985fb3aa7f77c9e8d63a2a179
1 // Copyright 2004-2008 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 using Castle.Components.Validator;
21 /// <summary>
22 /// Validate that the field has a value in a set of values.
23 /// </summary>
24 [Serializable, CLSCompliant(false)]
25 public class ValidateSetAttribute : AbstractValidationAttribute
27 private readonly IValidator validator;
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
31 /// </summary>
32 public ValidateSetAttribute() : base()
34 validator = new SetValidator();
37 /// <summary>
38 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
39 /// </summary>
40 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
41 public ValidateSetAttribute(string errorMessage) : base(errorMessage)
43 validator = new SetValidator();
46 /// <summary>
47 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
48 /// </summary>
49 /// <param name="set">The set of values to compare against.</param>
50 public ValidateSetAttribute(params string[] set) : base()
52 validator = new SetValidator(set);
55 /// <summary>
56 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
57 /// </summary>
58 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
59 /// <param name="set">The set of values to compare against.</param>
60 public ValidateSetAttribute(string errorMessage, params string[] set) : base(errorMessage)
62 validator = new SetValidator(set);
65 /// <summary>
66 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
67 /// </summary>
68 /// <param name="type">The <see cref="System.Type" /> of an <c>enum</c> class.
69 /// The enum names will be added to the contents of the set.</param>
70 public ValidateSetAttribute(Type type) : base()
72 validator = new SetValidator(type);
75 /// <summary>
76 /// Initializes a new instance of the <see cref="ValidateSetAttribute"/> class.
77 /// </summary>
78 /// <param name="type">The <see cref="System.Type" /> of an <c>enum</c> class.
79 /// The enum names will be added to the contents of the set.</param>
80 /// <param name="errorMessage">The error message to be displayed if the validation fails.</param>
81 public ValidateSetAttribute(Type type, string errorMessage) : base(errorMessage)
83 validator = new SetValidator(type);
86 /// <summary>
87 /// Constructs and configures an <see cref="IValidator"/>
88 /// instance based on the properties set on the attribute instance.
89 /// </summary>
90 /// <returns></returns>
91 public override IValidator Build()
93 ConfigureValidatorMessage(validator);
94 return validator;