| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Collections.ObjectModel; |
| | | 6 | | using System.Xml; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Description |
| | | 9 | | { |
| | | 10 | | public class PolicyAssertionCollection : Collection<XmlElement> |
| | | 11 | | { |
| | 1036 | 12 | | public PolicyAssertionCollection() { } |
| | | 13 | | |
| | 0 | 14 | | public PolicyAssertionCollection(IEnumerable<XmlElement> elements) |
| | | 15 | | { |
| | 0 | 16 | | if (elements == null) |
| | | 17 | | { |
| | 0 | 18 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements)); |
| | | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | AddRange(elements); |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | internal void AddRange(IEnumerable<XmlElement> elements) |
| | | 25 | | { |
| | 0 | 26 | | foreach (XmlElement element in elements) |
| | | 27 | | { |
| | 0 | 28 | | Add(element); |
| | | 29 | | } |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | public bool Contains(string localName, string namespaceUri) |
| | | 33 | | { |
| | 0 | 34 | | if (localName == null) |
| | | 35 | | { |
| | 0 | 36 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName)); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | if (namespaceUri == null) |
| | | 40 | | { |
| | 0 | 41 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(namespaceUri)); |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | for (int i = 0; i < Count; i++) |
| | | 45 | | { |
| | 0 | 46 | | XmlElement item = this[i]; |
| | 0 | 47 | | if (item.LocalName == localName && item.NamespaceURI == namespaceUri) |
| | | 48 | | { |
| | 0 | 49 | | return true; |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | return false; |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | public XmlElement Find(string localName, string namespaceUri) |
| | | 57 | | { |
| | 0 | 58 | | return Find(localName, namespaceUri, false); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public XmlElement Remove(string localName, string namespaceUri) |
| | | 62 | | { |
| | 0 | 63 | | return Find(localName, namespaceUri, true); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | private XmlElement Find(string localName, string namespaceUri, bool remove) |
| | | 67 | | { |
| | 0 | 68 | | if (localName == null) |
| | | 69 | | { |
| | 0 | 70 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName)); |
| | | 71 | | } |
| | | 72 | | |
| | 0 | 73 | | if (namespaceUri == null) |
| | | 74 | | { |
| | 0 | 75 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull((namespaceUri)); |
| | | 76 | | } |
| | | 77 | | |
| | 0 | 78 | | for (int index = 0; index < Count; index++) |
| | | 79 | | { |
| | 0 | 80 | | XmlElement item = this[index]; |
| | 0 | 81 | | if (item.LocalName == localName && item.NamespaceURI == namespaceUri) |
| | | 82 | | { |
| | 0 | 83 | | if (remove) |
| | | 84 | | { |
| | 0 | 85 | | RemoveAt(index); |
| | | 86 | | } |
| | 0 | 87 | | return item; |
| | | 88 | | } |
| | | 89 | | } |
| | | 90 | | |
| | 0 | 91 | | return null; |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | public Collection<XmlElement> FindAll(string localName, string namespaceUri) |
| | | 95 | | { |
| | 0 | 96 | | return FindAll(localName, namespaceUri, false); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | public Collection<XmlElement> RemoveAll(string localName, string namespaceUri) |
| | | 100 | | { |
| | 0 | 101 | | return FindAll(localName, namespaceUri, true); |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | private Collection<XmlElement> FindAll(string localName, string namespaceUri, bool remove) |
| | | 105 | | { |
| | 0 | 106 | | if (localName == null) |
| | | 107 | | { |
| | 0 | 108 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName)); |
| | | 109 | | } |
| | | 110 | | |
| | 0 | 111 | | if (namespaceUri == null) |
| | | 112 | | { |
| | 0 | 113 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(namespaceUri)); |
| | | 114 | | } |
| | | 115 | | |
| | 0 | 116 | | Collection<XmlElement> collection = new Collection<XmlElement>(); |
| | | 117 | | |
| | 0 | 118 | | for (int index = 0; index < Count; index++) |
| | | 119 | | { |
| | 0 | 120 | | XmlElement item = this[index]; |
| | 0 | 121 | | if (item.LocalName == localName && item.NamespaceURI == namespaceUri) |
| | | 122 | | { |
| | 0 | 123 | | if (remove) |
| | | 124 | | { |
| | 0 | 125 | | RemoveAt(index); |
| | | 126 | | // back up the index so we inspect the new item at this location |
| | 0 | 127 | | index--; |
| | | 128 | | } |
| | 0 | 129 | | collection.Add(item); |
| | | 130 | | } |
| | | 131 | | } |
| | | 132 | | |
| | 0 | 133 | | return collection; |
| | | 134 | | } |
| | | 135 | | |
| | | 136 | | protected override void InsertItem(int index, XmlElement item) |
| | | 137 | | { |
| | 100 | 138 | | if (item == null) |
| | | 139 | | { |
| | 0 | 140 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item)); |
| | | 141 | | } |
| | | 142 | | |
| | 100 | 143 | | base.InsertItem(index, item); |
| | 100 | 144 | | } |
| | | 145 | | |
| | | 146 | | protected override void SetItem(int index, XmlElement item) |
| | | 147 | | { |
| | 0 | 148 | | if (item == null) |
| | | 149 | | { |
| | 0 | 150 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item)); |
| | | 151 | | } |
| | | 152 | | |
| | 0 | 153 | | base.SetItem(index, item); |
| | 0 | 154 | | } |
| | | 155 | | } |
| | | 156 | | } |