SettingElement.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // System.Web.UI.WebControls.SettingElement.cs
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  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.
  27. //
  28. using System;
  29. namespace System.Configuration
  30. {
  31. public sealed class SettingElement
  32. #if (CONFIGURATION_DEP)
  33. : ConfigurationElement
  34. #endif
  35. {
  36. #if CONFIGURATION_DEP
  37. static ConfigurationPropertyCollection properties;
  38. static ConfigurationProperty name_prop, serialize_as_prop, value_prop;
  39. #endif
  40. static SettingElement ()
  41. {
  42. #if CONFIGURATION_DEP
  43. name_prop = new ConfigurationProperty ("name", typeof (string), String.Empty, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
  44. serialize_as_prop = new ConfigurationProperty ("serializeAs", typeof (SettingsSerializeAs), null, ConfigurationPropertyOptions.IsRequired);
  45. value_prop = new ConfigurationProperty ("value", typeof (SettingValueElement), null, ConfigurationPropertyOptions.IsRequired);
  46. properties = new ConfigurationPropertyCollection ();
  47. properties.Add (name_prop);
  48. properties.Add (serialize_as_prop);
  49. properties.Add (value_prop);
  50. #endif
  51. }
  52. public SettingElement ()
  53. {
  54. }
  55. public SettingElement (string name,
  56. SettingsSerializeAs serializeAs)
  57. {
  58. #if CONFIGURATION_DEP
  59. Name = name;
  60. SerializeAs = serializeAs;
  61. #endif
  62. }
  63. #if (CONFIGURATION_DEP)
  64. [ConfigurationProperty ("name", DefaultValue="",
  65. Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey)]
  66. public string Name {
  67. get { return (string) base [name_prop]; }
  68. set { base [name_prop] = value; } // it does not reject null
  69. }
  70. [ConfigurationProperty ("value", DefaultValue=null,
  71. Options = ConfigurationPropertyOptions.IsRequired)]
  72. public SettingValueElement Value {
  73. get { return (SettingValueElement) base [value_prop]; }
  74. set { base [value_prop] = value; }
  75. }
  76. [ConfigurationProperty ("serializeAs", DefaultValue=SettingsSerializeAs.String,
  77. Options = ConfigurationPropertyOptions.IsRequired)]
  78. public SettingsSerializeAs SerializeAs {
  79. get { return base [serialize_as_prop] != null ? (SettingsSerializeAs) base [serialize_as_prop] : default (SettingsSerializeAs); }
  80. set { base [serialize_as_prop] = value; }
  81. }
  82. protected override ConfigurationPropertyCollection Properties {
  83. get { return properties; }
  84. }
  85. public override bool Equals (object o)
  86. {
  87. SettingElement e = o as SettingElement;
  88. if (e == null)
  89. return false;
  90. return e.SerializeAs == SerializeAs && e.Value == Value && e.Name == Name;
  91. }
  92. public override int GetHashCode ()
  93. {
  94. int v = (int) SerializeAs ^ 0x7F;
  95. if (Name != null)
  96. v += Name.GetHashCode () ^ 0x7F;
  97. if (Value != null)
  98. v += Value.GetHashCode ();
  99. return v;
  100. }
  101. #endif
  102. }
  103. }