| | | 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.Configuration; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | public sealed class AddressHeaderCollectionElement : ServiceModelConfigurationElement |
| | | 11 | | { |
| | 0 | 12 | | public AddressHeaderCollectionElement() |
| | | 13 | | { |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | internal void Copy(AddressHeaderCollectionElement source) |
| | | 17 | | { |
| | 0 | 18 | | if (source == null) |
| | | 19 | | { |
| | 0 | 20 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(source)); |
| | | 21 | | } |
| | | 22 | | |
| | 0 | 23 | | PropertyInformationCollection properties = source.ElementInformation.Properties; |
| | 0 | 24 | | if (properties[ConfigurationStrings.Headers].ValueOrigin != PropertyValueOrigin.Default) |
| | | 25 | | { |
| | 0 | 26 | | Headers = source.Headers; |
| | | 27 | | } |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | [ConfigurationProperty(ConfigurationStrings.Headers, DefaultValue = null)] |
| | | 31 | | public AddressHeaderCollection Headers |
| | | 32 | | { |
| | | 33 | | get |
| | | 34 | | { |
| | 0 | 35 | | AddressHeaderCollection retVal = (AddressHeaderCollection)base[ConfigurationStrings.Headers]; |
| | 0 | 36 | | if (null == retVal) |
| | | 37 | | { |
| | 0 | 38 | | retVal = new AddressHeaderCollection(); |
| | | 39 | | } |
| | 0 | 40 | | return retVal; |
| | | 41 | | } |
| | | 42 | | set |
| | | 43 | | { |
| | 0 | 44 | | if (value == null) |
| | | 45 | | { |
| | 0 | 46 | | value = new AddressHeaderCollection(); |
| | | 47 | | } |
| | 0 | 48 | | base[ConfigurationStrings.Headers] = value; |
| | 0 | 49 | | } |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | |
| | | 53 | | protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) |
| | | 54 | | { |
| | 0 | 55 | | DeserializeElementCore(XmlDictionaryReader.CreateDictionaryReader(reader)); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | private void DeserializeElementCore(XmlDictionaryReader reader) |
| | | 59 | | { |
| | 0 | 60 | | Headers = new AddressHeaderCollection(new[] { new XmlElementBackedAddressHeader(reader) }); |
| | 0 | 61 | | } |
| | | 62 | | |
| | | 63 | | protected override bool SerializeToXmlElement(XmlWriter writer, string elementName) |
| | | 64 | | { |
| | 0 | 65 | | bool dataToWrite = Headers.Count != 0; |
| | 0 | 66 | | if (dataToWrite && writer != null) |
| | | 67 | | { |
| | 0 | 68 | | writer.WriteStartElement(elementName); |
| | | 69 | | |
| | 0 | 70 | | XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer); |
| | 0 | 71 | | foreach (AddressHeader header in Headers) |
| | | 72 | | { |
| | 0 | 73 | | header.WriteAddressHeader(dictionaryWriter); |
| | | 74 | | } |
| | | 75 | | |
| | 0 | 76 | | writer.WriteEndElement(); |
| | | 77 | | } |
| | 0 | 78 | | return dataToWrite; |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | internal void InitializeFrom(AddressHeaderCollection headers) |
| | | 82 | | { |
| | 0 | 83 | | SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Headers, headers); |
| | 0 | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |