Added tests for Task.WhenAll w/ empty list
[mono.git] / mcs / class / System.Configuration / System.Configuration / PropertyInformation.cs
1 //
2 // System.Configuration.PropertyInformation.cs
3 //
4 // Authors:
5 //  Lluis Sanchez Gual (lluis@novell.com)
6 //
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:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
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.
25 //
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
27 //
28
29 #if NET_2_0
30 using System.ComponentModel;
31
32 namespace System.Configuration
33 {
34         public sealed class PropertyInformation
35         {
36                 bool isLocked;
37                 bool isModified;
38                 int lineNumber;
39                 string source;
40                 object val;
41                 PropertyValueOrigin origin;
42                 readonly ConfigurationElement owner;
43                 readonly ConfigurationProperty property;
44                 
45                 internal PropertyInformation (ConfigurationElement owner, ConfigurationProperty property)
46                 {
47                         if (owner == null)
48                                 throw new ArgumentNullException ("owner");
49                         if (property == null)
50                                 throw new ArgumentNullException ("property");
51                         this.owner = owner;
52                         this.property = property;
53                 }
54                 
55                 public TypeConverter Converter {
56                         get { return property.Converter; }
57                 }
58                 
59                 public object DefaultValue {
60                         get { return property.DefaultValue; }
61                 }
62                 
63                 public string Description {
64                         get { return property.Description; }
65                 }
66                 
67                 public bool IsKey {
68                         get { return property.IsKey; }
69                 }
70                 
71                 [MonoTODO]
72                 public bool IsLocked {
73                         get { return isLocked; }
74                         internal set { isLocked = value; }
75                 }
76                 
77                 public bool IsModified {
78                         get { return isModified; }
79                         internal set { isModified = value; }
80                 }
81                 
82                 public bool IsRequired {
83                         get { return property.IsRequired; }
84                 }
85                 
86                 public int LineNumber {
87                         get { return lineNumber; }
88                         internal set { lineNumber = value; }
89                 }
90                 
91                 public string Name {
92                         get { return property.Name; }
93                 }
94                 
95                 public string Source {
96                         get { return source; }
97                         internal set { source = value; }
98                 }
99                 
100                 public Type Type {
101                         get { return property.Type; }
102                 }
103                 
104                 public ConfigurationValidatorBase Validator {
105                         get { return property.Validator; }
106                 }
107                 
108                 public object Value {
109                         get {
110                                 if (origin == PropertyValueOrigin.Default) {
111                                         if (property.IsElement) {
112                                                 ConfigurationElement elem = (ConfigurationElement) Activator.CreateInstance (Type, true);
113                                                 elem.InitFromProperty (this);
114                                                 if (owner != null && owner.IsReadOnly ())
115                                                         elem.SetReadOnly ();
116                                                 val = elem;
117                                                 origin = PropertyValueOrigin.Inherited;
118                                         }
119                                         else {
120                                                 return DefaultValue;
121                                         }
122                                 }
123                                 return val;
124                         }
125                         set {
126                                 val = value;
127                                 isModified = true;
128                                 origin = PropertyValueOrigin.SetHere;
129                         }
130                 }
131                 
132                 internal void Reset (PropertyInformation parentProperty)
133                 {
134                         if (parentProperty != null) {
135                                 if (property.IsElement) {
136                                         ((ConfigurationElement)Value).Reset ((ConfigurationElement) parentProperty.Value);
137                                 }
138                                 else {
139                                         val = parentProperty.Value;
140                                         origin = PropertyValueOrigin.Inherited;
141                                 }
142                         } else {
143                                 origin = PropertyValueOrigin.Default;
144                         }
145                 }
146                 
147                 internal bool IsElement {
148                         get { return property.IsElement; }
149                 }
150                 
151                 public PropertyValueOrigin ValueOrigin {
152                         get { return origin; }
153                 }
154                 
155                 internal string GetStringValue ()
156                 {
157                         return property.ConvertToString (Value);
158                 }
159                 
160                 internal void SetStringValue (string value)
161                 {
162                         val = property.ConvertFromString (value);
163                         if (!object.Equals (val, DefaultValue))
164                                 origin = PropertyValueOrigin.SetHere;
165                 }
166                 
167                 internal ConfigurationProperty Property {
168                         get { return property; }
169                 }
170         }
171 }
172 #endif