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 this.property = property;
51 public TypeConverter Converter {
52 get { return property.Converter; }
55 public object DefaultValue {
56 get { return property.DefaultValue; }
59 public string Description {
60 get { return property.Description; }
64 get { return property.IsKey; }
68 public bool IsLocked {
69 get { return isLocked; }
70 internal set { isLocked = value; }
73 public bool IsModified {
74 get { return isModified; }
75 internal set { isModified = value; }
78 public bool IsRequired {
79 get { return property.IsRequired; }
83 public int LineNumber {
84 get { return lineNumber; }
85 internal set { lineNumber = value; }
89 get { return property.Name; }
93 public string Source {
94 get { return source; }
95 internal set { source = value; }
99 get { return property.Type; }
102 public ConfigurationValidatorBase Validator {
103 get { return property.Validator; }
106 public object Value {
108 if (origin == PropertyValueOrigin.Default) {
109 if (property.IsElement) {
110 ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (Type, true);
111 elem.InitFromProperty (this);
112 if (owner != null && owner.IsReadOnly ())
115 origin = PropertyValueOrigin.Inherited;
126 origin = PropertyValueOrigin.SetHere;
130 internal void Reset (PropertyInformation parentProperty)
132 if (parentProperty != null) {
133 if (property.IsElement) {
134 ((ConfigurationElement)Value).Reset ((ConfigurationElement) parentProperty.Value);
137 val = parentProperty.Value;
138 origin = PropertyValueOrigin.Inherited;
141 origin = PropertyValueOrigin.Default;
145 internal bool IsElement {
146 get { return property.IsElement; }
149 public PropertyValueOrigin ValueOrigin {
150 get { return origin; }
153 internal string GetStringValue ()
155 return property.ConvertToString (Value);
158 internal void SetStringValue (string value)
160 val = property.ConvertFromString (value);
161 if (!object.Equals (val, DefaultValue))
162 origin = PropertyValueOrigin.SetHere;
165 internal ConfigurationProperty Property {
166 get { return property; }