AddressHeaderCollectionElement.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Configuration / AddressHeaderCollectionElement.cs / 1 / AddressHeaderCollectionElement.cs

                            //------------------------------------------------------------------------------ 
// 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;

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

        [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; 
            }
        }

        ///  
        /// 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) 
        ///  
        [SecurityCritical, SecurityTreatAsSafe]
        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) 
        {
            SetIsPresent();
            DeserializeElementCore(reader);
        } 

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

        /// 
        /// Critical - calls ConfigurationHelpers.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;
        } 
    }
} 
 

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK