| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Model\AttributeModel\XValidate.cs | - | 0,0 % | 0,0 % | 0,0 % |
|
1 | #region Copyright | |
2 | /* | |
3 | ShowX. Maps business objects into presentation layer. | |
4 | Copyright (C) 2005 Jesus Diaz. | |
5 | ||
6 | This library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | This library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with this library; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
19 | ||
20 | For project details see: http://showx.sourceforge.net | |
21 | */ | |
22 | #endregion | |
23 | ||
24 | using System; | |
25 | ||
26 | namespace ShowX.Model.AttributeModel | |
27 | { | |
28 | /// <summary> | |
29 | /// Attribute used to indicate type of validation to make over a certain instance. | |
30 | /// </summary> | |
31 | [AttributeUsage(AttributeTargets.Property,AllowMultiple=true)] | |
32 | public class XValidate : Attribute, IValidationMap | |
33 | { | |
34 | /// <summary> | |
35 | /// Type of validation to do over this instance. | |
36 | /// </summary> | |
37 | ValidateFor validateType; | |
38 | ||
39 | /// <summary> | |
40 | /// Regular expression string to validate this instance. | |
41 | /// </summary> | |
42 | string regularExpression; | |
43 | ||
44 | /// <summary> | |
45 | /// Type in wich this attribute is used to decorate certain property. This | |
46 | /// field is necessary to implement the Unique validation. | |
47 | /// </summary> | |
48 | Type type; | |
49 | ||
50 | /// <summary> | |
51 | /// Name of the property who has attached the attribute. This field is | |
52 | /// necessary to implement the Unique validation. | |
53 | /// </summary> | |
54 | string propertyName; | |
55 | ||
56 | /// <summary> | |
57 | /// Message to show if the validation fails. | |
58 | /// </summary> | |
59 | string message; | |
60 | ||
61 | /// <summary> | |
62 | /// Constructor. | |
63 | /// </summary> | |
64 | 0 | public XValidate() |
65 | { | |
66 | this.validateType = ValidateFor.NoValidation; | |
67 | this.regularExpression = string.Empty; | |
68 | this.propertyName = string.Empty; | |
69 | this.type = null; | |
70 | } | |
71 | ||
72 | ||
73 | #region IValidationMap Members | |
74 | ||
75 | /// <summary> | |
76 | /// Reflex the validateType attribute. | |
77 | /// </summary> | |
78 | 0 | public ValidateFor ValidateFor |
79 | { | |
80 | get { return this.validateType; } | |
81 | set { this.validateType = value; } | |
82 | } | |
83 | ||
84 | /// <summary> | |
85 | /// Reflex the message attribute. | |
86 | /// </summary> | |
87 | 0 | public string Message |
88 | { | |
89 | get { return this.message; } | |
90 | set { this.message = value; } | |
91 | } | |
92 | ||
93 | /// <summary> | |
94 | /// Reflex the regularExpression attribute. | |
95 | /// </summary> | |
96 | 0 | public string RegularExpression |
97 | { | |
98 | get { return this.regularExpression; } | |
99 | set { this.regularExpression = value; } | |
100 | } | |
101 | ||
102 | /// <summary> | |
103 | /// Reflex the type attribute. | |
104 | /// </summary> | |
105 | 0 | public Type Type |
106 | { | |
107 | get { return this.type; } | |
108 | set { this.type = value; } | |
109 | } | |
110 | ||
111 | /// <summary> | |
112 | /// Reflex the propertyName attribute. | |
113 | /// </summary> | |
114 | 0 | public string PropertyName |
115 | { | |
116 | get { return this.propertyName; } | |
117 | set { this.propertyName = value; } | |
118 | } | |
119 | ||
120 | /// <summary> | |
121 | /// Validate the input value, over the kind of validation defined here. The | |
122 | /// value is input as a string. | |
123 | /// </summary> | |
124 | /// <param name="context">Context in which occurs the operation (supplied by | |
125 | /// user via control properties)</param> | |
126 | /// <param name="s">Value to validate.</param> | |
127 | /// <returns>True if the value fulfills the requeriments of this validator. | |
128 | /// False otherwise.</returns> | |
129 | 0 | public bool Validate(object context,string s) |
130 | { | |
131 | return new InternalPropertyValidator().Validate(this,context,s); | |
132 | } | |
133 | ||
134 | #endregion | |
135 | } | |
136 | } |
|