2 // System.Configuration.PropertyInformation.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
30 using System.ComponentModel;
32 namespace System.Configuration
34 public sealed class PropertyInformation
41 PropertyValueOrigin origin;
42 readonly ConfigurationElement owner;
43 readonly ConfigurationProperty property;
45 internal PropertyInformation (ConfigurationElement owner, ConfigurationProperty property)
48 throw new ArgumentNullException ("owner");
50 throw new ArgumentNullException ("property");
52 this.property = property;
55 public TypeConverter Converter {
56 get { return property.Converter; }
59 public object DefaultValue {
60 get { return property.DefaultValue; }
63 public string Description {
64 get { return property.Description; }
68 get { return property.IsKey; }
72 public bool IsLocked {
73 get { return isLocked; }
74 internal set { isLocked = value; }
77 public bool IsModified {
78 get { return isModified; }
79 internal set { isModified = value; }
82 public bool IsRequired {
83 get { return property.IsRequired; }
87 public int LineNumber {
88 get { return lineNumber; }
89 internal set { lineNumber = value; }
93 get { return property.Name; }
97 public string Source {
98 get { return source; }
99 internal set { source = value; }
103 get { return property.Type; }
106 public ConfigurationValidatorBase Validator {
107 get { return property.Validator; }
110 public object Value {
112 if (origin == PropertyValueOrigin.Default) {
113 if (property.IsElement) {
114 ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (Type, true);
115 elem.InitFromProperty (this);
116 if (owner != null && owner.IsReadOnly ())
119 origin = PropertyValueOrigin.Inherited;
130 origin = PropertyValueOrigin.SetHere;
134 internal void Reset (PropertyInformation parentProperty)
136 if (parentProperty != null) {
137 if (property.IsElement) {
138 ((ConfigurationElement)Value).Reset ((ConfigurationElement) parentProperty.Value);
141 val = parentProperty.Value;
142 origin = PropertyValueOrigin.Inherited;
145 origin = PropertyValueOrigin.Default;
149 internal bool IsElement {
150 get { return property.IsElement; }
153 public PropertyValueOrigin ValueOrigin {
154 get { return origin; }
157 internal string GetStringValue ()
159 return property.ConvertToString (Value);
162 internal void SetStringValue (string value)
164 val = property.ConvertFromString (value);
165 if (!object.Equals (val, DefaultValue))
166 origin = PropertyValueOrigin.SetHere;
169 internal ConfigurationProperty Property {
170 get { return property; }