File: AddressHeaderCollectionElement.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (98 lines) | stat: -rw-r--r-- 3,500 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------------------------

namespace System.ServiceModel.Configuration
{
    using System;
    using System.Configuration;
    using System.ServiceModel.Channels;
    using System.Xml;
    using System.Security;
    using System.Runtime;

    public sealed partial class AddressHeaderCollectionElement : ServiceModelConfigurationElement
    {
        public AddressHeaderCollectionElement()
        {
        }

        internal void Copy(AddressHeaderCollectionElement source)
        {
            if (source == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
            }

            PropertyInformationCollection properties = source.ElementInformation.Properties;
            if (properties[ConfigurationStrings.Headers].ValueOrigin != PropertyValueOrigin.Default)
            {
                this.Headers = source.Headers;
            }
        }

        [ConfigurationProperty(ConfigurationStrings.Headers, DefaultValue = null)]
        public AddressHeaderCollection Headers
        {
            get
            {
                AddressHeaderCollection retVal = (AddressHeaderCollection)base[ConfigurationStrings.Headers];
                if (null == retVal)
                {
                    retVal = AddressHeaderCollection.EmptyHeaderCollection;
                }
                return retVal;
            }
            set
            {
                if (value == null)
                {
                    value = AddressHeaderCollection.EmptyHeaderCollection;
                }
                base[ConfigurationStrings.Headers] = value;
            }
        }

        [Fx.Tag.SecurityNote(Critical = "Uses the critical helper SetIsPresent.",
            Safe = "Controls how/when SetIsPresent is used, not arbitrarily callable from PT (method is protected and class is sealed).")]
        [SecuritySafeCritical]
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            SetIsPresent();
            DeserializeElementCore(reader);
        }

        private void DeserializeElementCore(XmlReader reader)
        {
            this.Headers = AddressHeaderCollection.ReadServiceParameters(XmlDictionaryReader.CreateDictionaryReader(reader));
        }

        [Fx.Tag.SecurityNote(Critical = "Uses the critical helper SetIsPresent which elevates in order to set a property.",
            Safe = "Only passes 'this', does not let caller influence parameter.")]
        [SecurityCritical]
        void SetIsPresent()
        {
            ConfigurationHelpers.SetIsPresent(this);
        }

        protected override bool SerializeToXmlElement(XmlWriter writer, String elementName)
        {
            bool dataToWrite = this.Headers.Count != 0;
            if (dataToWrite && writer != null)
            {
                writer.WriteStartElement(elementName);
                this.Headers.WriteContentsTo(XmlDictionaryWriter.CreateDictionaryWriter(writer));
                writer.WriteEndElement();
            }
            return dataToWrite;
        }

        internal void InitializeFrom(AddressHeaderCollection headers)
        {
            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Headers, headers);
        }
    }
}