2 // System.Web.UI.WebControls.SettingElement.cs
5 // Chris Toshok (toshok@ximian.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 namespace System
.Configuration
33 public sealed class SettingElement
34 #if (CONFIGURATION_DEP)
35 : ConfigurationElement
39 static ConfigurationPropertyCollection properties
;
40 static ConfigurationProperty name_prop
, serialize_as_prop
, value_prop
;
43 static SettingElement ()
46 name_prop
= new ConfigurationProperty ("name", typeof (string), String
.Empty
, ConfigurationPropertyOptions
.IsRequired
| ConfigurationPropertyOptions
.IsKey
);
47 serialize_as_prop
= new ConfigurationProperty ("serializeAs", typeof (SettingsSerializeAs
), null, ConfigurationPropertyOptions
.IsRequired
);
48 value_prop
= new ConfigurationProperty ("value", typeof (SettingValueElement
), null, ConfigurationPropertyOptions
.IsRequired
);
49 properties
= new ConfigurationPropertyCollection ();
51 properties
.Add (name_prop
);
52 properties
.Add (serialize_as_prop
);
53 properties
.Add (value_prop
);
57 public SettingElement ()
61 public SettingElement (string name
,
62 SettingsSerializeAs serializeAs
)
66 SerializeAs
= serializeAs
;
70 #if (CONFIGURATION_DEP)
71 [ConfigurationProperty ("name", DefaultValue
="",
72 Options
= ConfigurationPropertyOptions
.IsRequired
| ConfigurationPropertyOptions
.IsKey
)]
74 get { return (string) base [name_prop]; }
75 set { base [name_prop] = value; }
// it does not reject null
78 [ConfigurationProperty ("value", DefaultValue
=null,
79 Options
= ConfigurationPropertyOptions
.IsRequired
)]
80 public SettingValueElement Value
{
81 get { return (SettingValueElement) base [value_prop]; }
82 set { base [value_prop] = value; }
85 [ConfigurationProperty ("serializeAs", DefaultValue
=SettingsSerializeAs
.String
,
86 Options
= ConfigurationPropertyOptions
.IsRequired
)]
87 public SettingsSerializeAs SerializeAs
{
88 get { return base [serialize_as_prop] != null ? (SettingsSerializeAs) base [serialize_as_prop] : default (SettingsSerializeAs); }
89 set { base [serialize_as_prop] = value; }
92 protected override ConfigurationPropertyCollection Properties
{
93 get { return properties; }
96 public override bool Equals (object o
)
98 SettingElement e
= o
as SettingElement
;
102 return e
.SerializeAs
== SerializeAs
&& e
.Value
== Value
&& e
.Name
== Name
;
105 public override int GetHashCode ()
107 int v
= (int) SerializeAs ^
0x7F;
109 v
+= Name
.GetHashCode () ^
0x7F;
111 v
+= Value
.GetHashCode ();