File: RangeValidator.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (189 lines) | stat: -rw-r--r-- 7,761 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//------------------------------------------------------------------------------
// <copyright file="RangeValidator.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.Design.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using WebCntrls = System.Web.UI.WebControls;
using System.Security.Permissions;

namespace System.Web.UI.MobileControls
{
    /*
     * Mobile RangeValidator class.
     * The RangeValidator checks that the value of the associated input control
     * is within a minimum and maximum value.  These can either be constant
     * values or other input controls.  A data type property specifies how the
     * values being compared should be interpreted: Strings, integers, dates,
     * etc.
     *
     * Copyright (c) 2000 Microsoft Corporation
     */
    /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator"]/*' />
    [
        ToolboxData("<{0}:RangeValidator runat=\"server\" ErrorMessage=\"RangeValidator\"></{0}:RangeValidator>"),
        ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, " + AssemblyRef.SystemDesign)
    ]    
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
    public class RangeValidator : BaseValidator
    {
        private WebCntrls.RangeValidator _webRangeValidator;

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.CreateWebValidator"]/*' />
        protected override WebCntrls.BaseValidator CreateWebValidator()
        {
            _webRangeValidator = new WebCntrls.RangeValidator();
            return _webRangeValidator;
        }

        ////////////////////////////////////////////////////////////////////////
        // Mimic the properties exposed in the original RangeValidator.
        // The properties are got and set directly from the original RangeValidator.
        ////////////////////////////////////////////////////////////////////////

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.MaximumValue"]/*' />
        [
            Bindable(true),
            DefaultValue(""),
            MobileCategory(SR.Category_Behavior),
            MobileSysDescription(SR.RangeValidator_MaximumValue)
        ]
        public String MaximumValue
        {
            get
            {
                return _webRangeValidator.MaximumValue;
            }
            set
            {
                _webRangeValidator.MaximumValue = value;
            }
        }

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.MinimumValue"]/*' />
        [
            Bindable(true),
            DefaultValue(""),
            MobileCategory(SR.Category_Behavior),
            MobileSysDescription(SR.RangeValidator_MinimumValue)
        ]
        public String MinimumValue
        {
            get
            {
                return _webRangeValidator.MinimumValue;
            }
            set
            {
                _webRangeValidator.MinimumValue = value;
            }
        }

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.Type"]/*' />
        [
            Bindable(false),
            DefaultValue(ValidationDataType.String),
            MobileCategory(SR.Category_Behavior),
            MobileSysDescription(SR.RangeValidator_Type)
        ]
        public ValidationDataType Type
        {
            get
            {
                return _webRangeValidator.Type;
            }
            set
            {
                _webRangeValidator.Type = value;
            }
        }

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.EvaluateIsValid"]/*' />
        protected override bool EvaluateIsValid()
        {
            return EvaluateIsValidInternal();
        }

        /////////////////////////////////////////////////////////////////////
        // Helper function adopted from WebForms RangeValidator
        /////////////////////////////////////////////////////////////////////

        /// <include file='doc\RangeValidator.uex' path='docs/doc[@for="RangeValidator.ControlPropertiesValid"]/*' />
        protected override bool ControlPropertiesValid()
        {
            // Check if the control values can be converted to data type
            String maximumValue = MaximumValue;
            if (!WebCntrls.BaseCompareValidator.CanConvert(maximumValue, Type))
            {
                throw new ArgumentException(SR.GetString(
                        SR.Validator_ValueBadType,
                        maximumValue,
                        "MaximumValue",
                        ID,
                        PropertyConverter.EnumToString(
                            typeof(ValidationDataType), Type)
                ));
            }
            String minumumValue = MinimumValue;
            if (!WebCntrls.BaseCompareValidator.CanConvert(minumumValue, Type))
            {
                throw new ArgumentException(SR.GetString(
                        SR.Validator_ValueBadType,
                        minumumValue,
                        "MinimumValue",
                        ID,
                        PropertyConverter.EnumToString(
                            typeof(ValidationDataType), Type)
                ));
            }
            // Check for overlap.
            if (WebBaseCompareValidator.Compare(minumumValue, maximumValue,
                                ValidationCompareOperator.GreaterThan, Type))
            {
                throw new ArgumentException(SR.GetString(
                        SR.RangeValidator_RangeOverlap, maximumValue,
                        minumumValue, ID));
            }
            return base.ControlPropertiesValid();            
        }

        // The reason of having this class is to expose the method
        // BaseCompareValidator.Compare which is a protected method in the
        // base class.  Since the implementation of the method is not
        // trivial, instead of copying the code to this file, the following
        // subclass inherits the base class and expose a new public method
        // which calls its base implementation.  While this solution doesn't
        // look elegant, it helps eliminate the code maintanence issue of
        // copying the code.
        private class WebBaseCompareValidator : BaseCompareValidator
        {
            // Have to define this method since it is abstract in the base
            // class.
            protected override bool EvaluateIsValid()
            {
                Debug.Assert(false, "Should never be called.");
                return true;
            }

            public static new bool Compare(
                String leftText, String rightText,
                ValidationCompareOperator op, ValidationDataType type)
            {
                return BaseCompareValidator.Compare(leftText, rightText, op, type);
            }
        }
    }
}