ParameterElementCollection.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.Runtime.Serialization.Configuration
  5. {
  6. using System;
  7. using System.Configuration;
  8. using System.Globalization;
  9. [ConfigurationCollection(typeof(ParameterElement), AddItemName = ConfigurationStrings.Parameter, CollectionType = ConfigurationElementCollectionType.BasicMap)]
  10. public sealed class ParameterElementCollection : ConfigurationElementCollection
  11. {
  12. public ParameterElementCollection()
  13. {
  14. this.AddElementName = ConfigurationStrings.Parameter;
  15. }
  16. public ParameterElement this[int index]
  17. {
  18. get
  19. {
  20. ParameterElement retval = (ParameterElement)BaseGet(index);
  21. return retval;
  22. }
  23. set
  24. {
  25. // Only validate input if config is not Read-Only, otherwise
  26. // let BaseAdd throw appropriate exception
  27. if (!this.IsReadOnly())
  28. {
  29. if (value == null)
  30. {
  31. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
  32. }
  33. if (BaseGet(index) != null)
  34. {
  35. BaseRemoveAt(index);
  36. }
  37. }
  38. BaseAdd(index, value);
  39. }
  40. }
  41. public void Add(ParameterElement element)
  42. {
  43. // Only validate input if config is not Read-Only, otherwise
  44. // let BaseAdd throw appropriate exception
  45. if (!this.IsReadOnly())
  46. {
  47. if (element == null)
  48. {
  49. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
  50. }
  51. }
  52. BaseAdd(element);
  53. }
  54. public void Clear()
  55. {
  56. BaseClear();
  57. }
  58. public override ConfigurationElementCollectionType CollectionType
  59. {
  60. get { return ConfigurationElementCollectionType.BasicMap; }
  61. }
  62. public bool Contains(string typeName)
  63. {
  64. if (String.IsNullOrEmpty(typeName))
  65. {
  66. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("typeName");
  67. }
  68. return this.BaseGet(typeName) != null;
  69. }
  70. protected override ConfigurationElement CreateNewElement()
  71. {
  72. ParameterElement retval = new ParameterElement();
  73. return retval;
  74. }
  75. protected override string ElementName
  76. {
  77. get { return ConfigurationStrings.Parameter; }
  78. }
  79. protected override Object GetElementKey(ConfigurationElement element)
  80. {
  81. if (element == null)
  82. {
  83. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
  84. }
  85. return ((ParameterElement)element).identity;
  86. }
  87. public int IndexOf(ParameterElement element)
  88. {
  89. if (element == null)
  90. {
  91. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
  92. }
  93. return BaseIndexOf(element);
  94. }
  95. public void Remove(ParameterElement element)
  96. {
  97. // Only validate input if config is not Read-Only, otherwise
  98. // let BaseRemove throw appropriate exception
  99. if (!this.IsReadOnly())
  100. {
  101. if (element == null)
  102. {
  103. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
  104. }
  105. }
  106. BaseRemove(this.GetElementKey(element));
  107. }
  108. public void RemoveAt(int index)
  109. {
  110. BaseRemoveAt(index);
  111. }
  112. }
  113. }