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 ConfigurationElement owner;
44 ConfigurationProperty property;
46 internal PropertyInformation (ConfigurationElement owner, ConfigurationProperty property)
49 this.property = property;
52 public TypeConverter Converter {
53 get { return property.Converter; }
56 public object DefaultValue {
57 get { return property.DefaultValue; }
60 public string Description {
61 get { return property.Description; }
65 get { return property.IsKey; }
69 public bool IsLocked {
70 get { return isLocked; }
71 internal set { isLocked = value; }
74 public bool IsModified {
75 get { return isModified; }
76 internal set { isModified = value; }
79 public bool IsRequired {
80 get { return property.IsRequired; }
84 public int LineNumber {
85 get { return lineNumber; }
86 internal set { lineNumber = value; }
90 get { return property.Name; }
94 public string Source {
95 get { return source; }
96 internal set { source = value; }
100 get { return property.Type; }
103 public ConfigurationValidatorBase Validator {
104 get { return property.Validator; }
107 public object Value {
109 if (origin == PropertyValueOrigin.Default) {
110 if (property.IsElement) {
111 ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (Type);
112 elem.InitFromProperty (this);
113 if (owner != null && owner.IsReadOnly ())
116 origin = PropertyValueOrigin.Inherited;
127 origin = PropertyValueOrigin.SetHere;
131 internal void Reset (PropertyInformation parentProperty)
133 if (parentProperty != null) {
134 if (property.IsElement) {
135 ((ConfigurationElement)Value).Reset ((ConfigurationElement) parentProperty.Value);
138 val = parentProperty.Value;
139 origin = PropertyValueOrigin.Inherited;
142 origin = PropertyValueOrigin.Default;
146 internal bool IsElement {
147 get { return property.IsElement; }
150 public PropertyValueOrigin ValueOrigin {
151 get { return origin; }
154 internal string GetStringValue ()
156 return property.ConvertToString (Value);
159 internal void SetStringValue (string value)
161 val = property.ConvertFromString (value);
162 if (!object.Equals (val, DefaultValue))
163 origin = PropertyValueOrigin.SetHere;
166 internal ConfigurationProperty Property {
167 get { return property; }