2 // System.Configuration.ConfigurationProperty.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
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:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
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.
27 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
32 using System.ComponentModel;
34 namespace System.Configuration
36 public sealed class ConfigurationProperty
38 internal static object NoDefaultValue = new object ();
42 object default_value = NoDefaultValue;
43 TypeConverter converter;
44 ConfigurationValidatorBase validation;
45 ConfigurationPropertyOptions flags;
47 ConfigurationCollectionAttribute collectionAttribute;
49 public ConfigurationProperty (string name, Type type)
50 : this (name, type, NoDefaultValue, TypeDescriptor.GetConverter (type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
53 public ConfigurationProperty (string name, Type type, object default_value)
54 : this (name, type, default_value, TypeDescriptor.GetConverter (type), new DefaultValidator(), ConfigurationPropertyOptions.None, null)
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)
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)
71 public ConfigurationProperty (
72 string name, Type type, object default_value,
73 TypeConverter converter,
74 ConfigurationValidatorBase validation,
75 ConfigurationPropertyOptions flags,
79 this.converter = converter;
80 this.default_value = default_value;
83 this.validation = validation;
84 this.description = description;
87 public TypeConverter Converter {
88 get { return converter; }
91 public object DefaultValue {
92 get { return default_value; }
96 get { return (flags & ConfigurationPropertyOptions.IsKey) != 0; }
99 public bool IsRequired {
100 get { return (flags & ConfigurationPropertyOptions.IsRequired) != 0; }
103 public bool IsDefaultCollection {
104 get { return (flags & ConfigurationPropertyOptions.IsDefaultCollection) != 0; }
111 public string Description {
112 get { return description; }
119 public ConfigurationValidatorBase Validator {
120 get { return validation; }
123 internal object ConvertFromString (string value)
125 if (converter != null)
126 return converter.ConvertFromInvariantString (value);
128 throw new NotImplementedException ();
131 internal string ConvertToString (object value)
133 if (converter != null)
134 return converter.ConvertToInvariantString (value);
136 throw new NotImplementedException ();
139 internal bool IsElement {
141 return (typeof(ConfigurationElement).IsAssignableFrom (type));
145 internal ConfigurationCollectionAttribute CollectionAttribute {
146 get { return collectionAttribute; }
147 set { collectionAttribute = value; }
150 internal void Validate (object value)
152 if (validation != null)
153 validation.Validate (value);