XmlElementElementCollection.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System;
  7. using System.Collections;
  8. using System.Configuration;
  9. using System.Globalization;
  10. using System.Xml;
  11. [ConfigurationCollection(typeof(XmlElementElement), AddItemName = ConfigurationStrings.XmlElement, CollectionType = ConfigurationElementCollectionType.BasicMap)]
  12. public sealed class XmlElementElementCollection : ServiceModelConfigurationElementCollection<XmlElementElement>
  13. {
  14. public XmlElementElementCollection()
  15. : base(ConfigurationElementCollectionType.BasicMap, ConfigurationStrings.XmlElement)
  16. { }
  17. protected override Object GetElementKey(ConfigurationElement element)
  18. {
  19. if (element == null)
  20. {
  21. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
  22. }
  23. return ((XmlElementElement)element).XmlElement.OuterXml;
  24. }
  25. protected override void Unmerge(ConfigurationElement sourceElement,
  26. ConfigurationElement parentElement,
  27. ConfigurationSaveMode saveMode)
  28. {
  29. if (sourceElement != null)
  30. {
  31. // Just copy from parent to here--
  32. XmlElementElementCollection source = (XmlElementElementCollection)sourceElement;
  33. XmlElementElementCollection parent = (XmlElementElementCollection)parentElement;
  34. for (int i = 0; i < source.Count; ++i)
  35. {
  36. XmlElementElement element = source[i];
  37. if ((parent == null) || !parent.ContainsKey(this.GetElementKey(element)))
  38. {
  39. XmlElementElement xmlElement = new XmlElementElement();
  40. xmlElement.ResetInternal(element);
  41. this.Add(xmlElement);
  42. }
  43. }
  44. }
  45. }
  46. protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
  47. {
  48. XmlDocument doc = new XmlDocument();
  49. this.Add(new XmlElementElement((XmlElement)doc.ReadNode(reader)));
  50. return true;
  51. }
  52. }
  53. }