ConfigurationProperty.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // System.Configuration.ConfigurationProperty.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  28. //
  29. #if NET_2_0 && XML_DEP
  30. #if XML_DEP
  31. using System;
  32. using System.ComponentModel;
  33. namespace System.Configuration
  34. {
  35. public class ConfigurationProperty : ConfigurationElement
  36. {
  37. string name;
  38. Type type;
  39. object default_value;
  40. TypeConverter converter;
  41. ConfigurationValidationAttribute validation;
  42. ConfigurationPropertyFlags flags;
  43. public ConfigurationProperty (string name, Type type, object default_value)
  44. : this (name, type, default_value, ConfigurationPropertyFlags.None)
  45. {
  46. }
  47. public ConfigurationProperty (
  48. string name, Type type, object default_value,
  49. ConfigurationPropertyFlags flags)
  50. :this (name, type, default_value, TypeDescriptor.GetConverter (type), null, flags)
  51. {
  52. }
  53. public ConfigurationProperty (
  54. string name, Type type, object default_value,
  55. TypeConverter converter,
  56. ConfigurationValidationAttribute validation,
  57. ConfigurationPropertyFlags flags)
  58. {
  59. this.name = name;
  60. this.converter = converter;
  61. this.default_value = default_value;
  62. this.flags = flags;
  63. this.type = type;
  64. this.validation = validation;
  65. }
  66. public TypeConverter Converter {
  67. get { return converter; }
  68. }
  69. public object DefaultValue {
  70. get { return default_value; }
  71. }
  72. public bool IsKey {
  73. get { return (flags & ConfigurationPropertyFlags.IsKey) != 0; }
  74. }
  75. public bool IsRequired {
  76. get { return (flags & ConfigurationPropertyFlags.Required) != 0; }
  77. }
  78. public string Name {
  79. get { return name; }
  80. }
  81. public Type Type {
  82. get { return type; }
  83. }
  84. public ConfigurationValidationAttribute ValidationAttribute {
  85. get { return validation; }
  86. }
  87. protected internal virtual object ConvertFromString (string value)
  88. {
  89. if (converter != null)
  90. return converter.ConvertFromInvariantString (value);
  91. else
  92. throw new NotImplementedException ();
  93. }
  94. protected internal virtual string ConvertToString (object value)
  95. {
  96. if (converter != null)
  97. return converter.ConvertToInvariantString (value);
  98. else
  99. throw new NotImplementedException ();
  100. }
  101. internal bool IsElement {
  102. get {
  103. return (typeof(ConfigurationElement).IsAssignableFrom (type));
  104. }
  105. }
  106. }
  107. }
  108. #endif
  109. #endif