ServiceModelExtensionCollectionElement.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // ServiceModelExtensionCollectionElement.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 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. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Configuration;
  32. namespace System.ServiceModel.Configuration
  33. {
  34. [MonoTODO]
  35. public class ServiceModelExtensionCollectionElement<TServiceModelExtensionElement>
  36. : ConfigurationElement,
  37. ICollection<TServiceModelExtensionElement>,
  38. IEnumerable<TServiceModelExtensionElement>,
  39. IEnumerable
  40. where TServiceModelExtensionElement : ServiceModelExtensionElement
  41. {
  42. KeyedByTypeCollection<TServiceModelExtensionElement> _list = new KeyedByTypeCollection<TServiceModelExtensionElement> ();
  43. public virtual void Add (TServiceModelExtensionElement element)
  44. {
  45. _list.Add (element);
  46. }
  47. public virtual bool CanAdd (TServiceModelExtensionElement element) {
  48. throw new NotImplementedException ();
  49. }
  50. public void Clear ()
  51. {
  52. _list.Clear ();
  53. }
  54. public bool Contains (TServiceModelExtensionElement element)
  55. {
  56. return _list.Contains (element);
  57. }
  58. public bool ContainsKey (string elementName)
  59. {
  60. throw new NotImplementedException ();
  61. }
  62. public bool ContainsKey (Type elementType)
  63. {
  64. return _list.Contains (elementType);
  65. }
  66. public void CopyTo (TServiceModelExtensionElement[] elements,
  67. int start)
  68. {
  69. throw new NotImplementedException ();
  70. }
  71. public IEnumerator<TServiceModelExtensionElement> GetEnumerator () {
  72. for (int i = 0; i < Count; i++)
  73. yield return this [i];
  74. }
  75. public bool Remove (TServiceModelExtensionElement element) {
  76. return _list.Remove (element.GetType ());
  77. }
  78. IEnumerator IEnumerable.GetEnumerator ()
  79. {
  80. return GetEnumerator ();
  81. }
  82. bool ICollection<TServiceModelExtensionElement>.IsReadOnly {
  83. get { throw new NotImplementedException (); }
  84. }
  85. public TServiceModelExtensionElement this [int index] {
  86. get {
  87. return _list [index];
  88. }
  89. }
  90. public TServiceModelExtensionElement this [Type extensionType] {
  91. get {
  92. if (_list.Contains (extensionType))
  93. return _list [extensionType];
  94. return null;
  95. }
  96. }
  97. protected override void DeserializeElement (System.Xml.XmlReader reader, bool serializeCollectionKey) {
  98. base.DeserializeElement (reader, serializeCollectionKey);
  99. }
  100. protected override bool OnDeserializeUnrecognizedElement (string elementName, System.Xml.XmlReader reader) {
  101. TServiceModelExtensionElement ext= DeserializeExtensionElement (elementName, reader);
  102. if (ext == null)
  103. return false;
  104. Add (ext);
  105. return true;
  106. }
  107. internal virtual TServiceModelExtensionElement DeserializeExtensionElement (string elementName, System.Xml.XmlReader reader) {
  108. return null;
  109. }
  110. public int Count {
  111. get { return _list.Count; }
  112. }
  113. }
  114. }