2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System / System.Configuration / SettingElement.cs
blobf8914f95e580e980a110b7ff24c6f5ab0b4153c6
1 //
2 // System.Web.UI.WebControls.SettingElement.cs
3 //
4 // Authors:
5 // Chris Toshok (toshok@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #if NET_2_0
30 using System;
32 namespace System.Configuration
34 public sealed class SettingElement
35 #if (CONFIGURATION_DEP)
36 : ConfigurationElement
37 #endif
39 #if CONFIGURATION_DEP
40 static ConfigurationPropertyCollection properties;
41 static ConfigurationProperty name_prop, serialize_as_prop, value_prop;
42 #endif
44 static SettingElement ()
46 #if CONFIGURATION_DEP
47 name_prop = new ConfigurationProperty ("name", typeof (string), String.Empty, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
48 serialize_as_prop = new ConfigurationProperty ("serializeAs", typeof (SettingsSerializeAs), null, ConfigurationPropertyOptions.IsRequired);
49 value_prop = new ConfigurationProperty ("value", typeof (SettingValueElement), null, ConfigurationPropertyOptions.IsRequired);
50 properties = new ConfigurationPropertyCollection ();
52 properties.Add (name_prop);
53 properties.Add (serialize_as_prop);
54 properties.Add (value_prop);
55 #endif
58 public SettingElement ()
62 public SettingElement (string name,
63 SettingsSerializeAs serializeAs)
65 #if CONFIGURATION_DEP
66 Name = name;
67 SerializeAs = serializeAs;
68 #endif
71 #if (CONFIGURATION_DEP)
72 [ConfigurationProperty ("name", DefaultValue="",
73 Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
74 public string Name {
75 get { return (string) base [name_prop]; }
76 set { base [name_prop] = value; } // it does not reject null
79 [ConfigurationProperty ("value", DefaultValue=null,
80 Options = ConfigurationPropertyOptions.IsRequired)]
81 public SettingValueElement Value {
82 get { return (SettingValueElement) base [value_prop]; }
83 set { base [value_prop] = value; }
86 [ConfigurationProperty ("serializeAs", DefaultValue=SettingsSerializeAs.String,
87 Options = ConfigurationPropertyOptions.IsRequired)]
88 public SettingsSerializeAs SerializeAs {
89 get { return base [serialize_as_prop] != null ? (SettingsSerializeAs) base [serialize_as_prop] : default (SettingsSerializeAs); }
90 set { base [serialize_as_prop] = value; }
93 protected override ConfigurationPropertyCollection Properties {
94 get { return properties; }
97 public override bool Equals (object o)
99 SettingElement e = o as SettingElement;
100 if (e == null)
101 return false;
103 return e.SerializeAs == SerializeAs && e.Value == Value && e.Name == Name;
106 public override int GetHashCode ()
108 int v = (int) SerializeAs ^ 0x7F;
109 if (Name != null)
110 v += Name.GetHashCode () ^ 0x7F;
111 if (Value != null)
112 v += Value.GetHashCode ();
113 return v;
115 #endif
120 #endif