* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConfigurationProperty.cs
1 //
2 // System.Configuration.ConfigurationProperty.cs
3 //
4 // Authors:
5 //      Duncan Mak (duncan@ximian.com)
6 //  Lluis Sanchez Gual (lluis@novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
28 //
29
30 #if NET_2_0
31 using System;
32 using System.ComponentModel;
33
34 namespace System.Configuration
35 {
36         public sealed class ConfigurationProperty
37         {
38                 internal static object NoDefaultValue = new object ();
39                 
40                 string name;
41                 Type type;
42                 object default_value = NoDefaultValue;
43                 TypeConverter converter;
44                 ConfigurationValidatorBase validation;
45                 ConfigurationPropertyOptions flags;
46                 string description;
47                 ConfigurationCollectionAttribute collectionAttribute;
48                 
49                 public ConfigurationProperty (string name, Type type)
50                         : this (name, type, NoDefaultValue, TypeDescriptor.GetConverter (type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
51                 { }
52
53                 public ConfigurationProperty (string name, Type type, object default_value)
54                         : this (name, type, default_value, TypeDescriptor.GetConverter (type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
55                 { }
56
57                 public ConfigurationProperty (
58                                         string name, Type type, object default_value,
59                                         ConfigurationPropertyOptions flags)
60                         :this (name, type, default_value, TypeDescriptor.GetConverter (type), new DefaultValidator(), flags, null)
61                 { }
62                 
63                 public ConfigurationProperty (
64                                         string name, Type type, object default_value,
65                                         TypeConverter converter,
66                                         ConfigurationValidatorBase validation,
67                                         ConfigurationPropertyOptions flags)
68                         : this (name, type, default_value, converter, validation, flags, null)
69                 { }
70
71                 public ConfigurationProperty (
72                                         string name, Type type, object default_value,
73                                         TypeConverter converter,
74                                         ConfigurationValidatorBase validation,
75                                         ConfigurationPropertyOptions flags,
76                                         string description)
77                 {
78                         this.name = name;
79                         this.converter = converter;
80                         this.default_value = default_value;
81                         this.flags = flags;
82                         this.type = type;
83                         this.validation = validation;
84                         this.description = description;
85                 }
86
87                 public TypeConverter Converter {
88                         get { return converter; }
89                 }
90
91                 public object DefaultValue {                        
92                         get { return default_value; }
93                 }
94
95                 public bool IsKey {                        
96                         get { return (flags & ConfigurationPropertyOptions.IsKey) != 0; }
97                 }
98
99                 public bool IsRequired {
100                         get { return (flags & ConfigurationPropertyOptions.IsRequired) != 0; }
101                 }
102
103                 public bool IsDefaultCollection {
104                         get { return (flags & ConfigurationPropertyOptions.IsDefaultCollection) != 0; }
105                 }
106
107                 public string Name {
108                         get { return name; }
109                 }
110
111                 public string Description {
112                         get { return description; }
113                 }
114
115                 public Type Type {
116                         get { return type; }
117                 }
118
119                 public ConfigurationValidatorBase Validator {
120                         get { return validation; }
121                 }
122
123                 internal object ConvertFromString (string value)
124                 {
125                         if (converter != null)
126                                 return converter.ConvertFromInvariantString (value);
127                         else
128                                 throw new NotImplementedException ();
129                 }
130
131                 internal string ConvertToString (object value)
132                 {
133                         if (converter != null)
134                                 return converter.ConvertToInvariantString (value);
135                         else
136                                 throw new NotImplementedException ();
137                 }
138                 
139                 internal bool IsElement {
140                         get {
141                                 return (typeof(ConfigurationElement).IsAssignableFrom (type));
142                         }
143                 }
144                 
145                 internal ConfigurationCollectionAttribute CollectionAttribute {
146                         get { return collectionAttribute; }
147                         set { collectionAttribute = value; }
148                 }
149
150                 internal void Validate (object value)
151                 {
152                         if (validation != null)
153                                 validation.Validate (value);
154                 }
155         }
156 }
157 #endif