Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Components / Validator / Castle.Components.Validator / IValidator.cs
blob42c477d944c463364e3703d45a179cc136dafae6
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.Collections;
18 using System.Reflection;
20 /// <summary>
21 /// Defines the basic contract for validators.
22 /// <para>
23 /// To create a new validation you should use <see cref="AbstractValidator"/> as it
24 /// implements most of the common methods and properties.
25 /// </para>
26 /// <para>
27 /// The validation should happen at <c>IsValid</c>, and if the validator can configure
28 /// a client-side validation script, it should use the <see cref="SupportsBrowserValidation"/>
29 /// to indicate that it does support client-side validation and also implement the
30 /// <see cref="ApplyBrowserValidation"/> to configure it.
31 /// </para>
32 /// </summary>
33 public interface IValidator
35 /// <summary>
36 /// Implementors should perform any initialization logic
37 /// </summary>
38 /// <param name="validationRegistry">The validation registry.</param>
39 /// <param name="property">The target property</param>
40 void Initialize(IValidatorRegistry validationRegistry, PropertyInfo property);
42 /// <summary>
43 /// The target property
44 /// </summary>
45 PropertyInfo Property { get; }
47 /// <summary>
48 /// Defines when to run the validation.
49 /// Defaults to <c>RunWhen.Everytime</c>
50 /// </summary>
51 RunWhen RunWhen { get; set; }
53 /// <summary>
54 /// Gets or sets the validation execution order.
55 /// </summary>
56 /// <value>The execution order.</value>
57 int ExecutionOrder { get; set; }
59 /// <summary>
60 /// The error message to be displayed if the validation fails
61 /// </summary>
62 /// <value>The error message.</value>
63 string ErrorMessage { get; set; }
65 /// <summary>
66 /// Gets or sets the a friendly name for the target property
67 /// </summary>
68 /// <value>The name.</value>
69 string FriendlyName { get; set; }
71 /// <summary>
72 /// Implementors should perform the actual validation upon
73 /// the property value
74 /// </summary>
75 /// <param name="instance"></param>
76 /// <returns><c>true</c> if the field is OK</returns>
77 bool IsValid(object instance);
79 /// <summary>
80 /// Implementors should perform the actual validation upon
81 /// the property value
82 /// </summary>
83 /// <param name="instance"></param>
84 /// <param name="fieldValue"></param>
85 /// <returns><c>true</c> if the field is OK</returns>
86 bool IsValid(object instance, object fieldValue);
88 /// <summary>
89 /// Gets a value indicating whether this validator supports browser validation.
90 /// </summary>
91 /// <value>
92 /// <see langword="true"/> if browser validation is supported; otherwise, <see langword="false"/>.
93 /// </value>
94 bool SupportsBrowserValidation { get; }
96 /// <summary>
97 /// Applies the browser validation by setting up one or
98 /// more input rules on <see cref="IBrowserValidationGenerator"/>.
99 /// </summary>
100 /// <param name="config">The config.</param>
101 /// <param name="inputType">Type of the input.</param>
102 /// <param name="generator">The generator.</param>
103 /// <param name="attributes">The attributes.</param>
104 /// <param name="target">The target.</param>
105 void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
106 IBrowserValidationGenerator generator, IDictionary attributes, string target);
108 /// <summary>
109 /// Gets the property name. The <see cref="FriendlyName"/>
110 /// is returned if non-null, otherwise it will return the property name.
111 /// </summary>
112 string Name { get; }