Skip to main content
.NET Framework Class Library
ConfigurationElement Class

Represents a configuration element within a configuration file.

Inheritance Hierarchy
SystemObject
  System.ConfigurationConfigurationElement
    More...

Namespace:   System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
Syntax
Public MustInherit Class ConfigurationElement
public abstract class ConfigurationElement
public ref class ConfigurationElement abstract
[<[%$TOPIC/kyx77cz3_en-us_VS_110_2_0_3_0_0%]>]
type ConfigurationElement =  class end

The ConfigurationElement type exposes the following members.

Constructors
  NameDescription
Protected method ConfigurationElementInitializes a new instance of the ConfigurationElement class.
Top
Properties
  NameDescription
Public property CurrentConfigurationGets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to.
Public property ElementInformationGets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object.
Protected property ElementPropertyGets the ConfigurationElementProperty object that represents the ConfigurationElement object itself.
Protected property EvaluationContextGets the ContextInformation object for the ConfigurationElement object.
Protected property HasContextGets a value that indicates whether the CurrentConfiguration property is .
Protected property ItemConfigurationPropertyGets or sets a property or attribute of this configuration element.
Protected property ItemStringGets or sets a property, attribute, or child element of this configuration element.
Public property LockAllAttributesExceptGets the collection of locked attributes.
Public property LockAllElementsExceptGets the collection of locked elements.
Public property LockAttributesGets the collection of locked attributes
Public property LockElementsGets the collection of locked elements.
Public property LockItemGets or sets a value indicating whether the element is locked.
Protected property PropertiesGets the collection of properties.
Top
Methods
  NameDescription
Protected method DeserializeElementReads XML from the configuration file.
Public method EqualsCompares the current ConfigurationElement instance to the specified object. (Overrides ObjectEquals(Object).)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeGets a unique value representing the current ConfigurationElement instance. (Overrides ObjectGetHashCode.)
Protected method GetTransformedAssemblyStringReturns the transformed version of the specified assembly name.
Protected method GetTransformedTypeStringReturns the transformed version of the specified type name.
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method InitSets the ConfigurationElement object to its initial state.
Protected method InitializeDefaultUsed to initialize a default set of values for the ConfigurationElement object.
Protected method IsModifiedIndicates whether this configuration element has been modified since it was last saved or loaded, when implemented in a derived class.
Public method IsReadOnlyGets a value indicating whether the ConfigurationElement object is read-only.
Protected method ListErrorsAdds the invalid-property errors in this ConfigurationElement object, and in all subelements, to the passed list.
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnDeserializeUnrecognizedAttributeGets a value indicating whether an unknown attribute is encountered during deserialization.
Protected method OnDeserializeUnrecognizedElementGets a value indicating whether an unknown element is encountered during deserialization.
Protected method OnRequiredPropertyNotFoundThrows an exception when a required property is not found.
Protected method PostDeserializeCalled after deserialization.
Protected method PreSerializeCalled before serialization.
Protected method ResetResets the internal state of the ConfigurationElement object, including the locks and the properties collections.
Protected method ResetModifiedResets the value of the IsModified method to false when implemented in a derived class.
Protected method SerializeElementWrites the contents of this configuration element to the configuration file when implemented in a derived class.
Protected method SerializeToXmlElementWrites the outer tags of this configuration element to the configuration file when implemented in a derived class.
Protected method SetPropertyValueSets a property to the specified value.
Protected method SetReadOnlySets the IsReadOnly property for the ConfigurationElement object and all subelements.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Protected method UnmergeModifies the ConfigurationElement object to remove all values that should not be saved.
Top
Remarks

The ConfigurationElement is an abstract class that is used to represent an XML element in a configuration file (such as Web.config). An element in a configuration file can contain zero, one, or more child elements.

Because the ConfigurationElement class is defined as abstract, you cannot create an instance of it. You can only derive classes from it. The .NET Framework includes classes that derive from the ConfigurationElement class in order to represent standard XML configuration elements, such as ConfigurationSection. You can also extend the ConfigurationElement class to access custom configuration elements and sections. The example included later in this topic shows how to access custom configuration elements and sections by using custom classes that derive from ConfigurationElement.

You can also extend the standard configuration types such as ConfigurationElement, ConfigurationElementCollection, ConfigurationProperty, and ConfigurationSection. For more information, see the documentation for those classes.

For more information about how to access information in configuration files, see the ConfigurationManager class and the WebConfigurationManager class.

Notes to Inheritors

Every ConfigurationElement object creates an internal ConfigurationPropertyCollection collection of ConfigurationProperty objects that represents either the element attributes or a collection of child elements.

Non-customizable information and functionality is contained by an ElementInformation object provided by the ElementInformation property.

You can use either a programmatic or a declarative (attributed) coding model to create a custom configuration element:

  • The programmatic model requires that for each element attribute, you create a property to get or set its value and add it to the internal property bag of the underlying ConfigurationElement base class. For an example of how to use this model, see the ConfigurationSection class.

  • The simpler declarative model, also called the attributed model, allows you to define an element attribute by using a property and then decorate it with attributes. These attributes instruct the ASP.NET configuration system about the property types and their default values. With this information, obtained through reflection, the ASP.NET configuration system creates the element property objects for you and performs the required initialization. The example shown later in this topic shows how to use this model.

Examples

The following code example shows how to implement a custom ConfigurationElement both as an individual element in a custom section and as a collection of elements in a custom section. The example consists of the following files:

  • An app.config file that contains a custom section that is named MyUrls. This section contains a simple element (it does not contain any other elements) and a collection of elements. The simple element is named simple and the collection is named urls.

  • A console application. The application reads the contents of the app.config file and writes the information to the console. It uses classes that derive from ConfigurationElement, ConfigurationElementCollection, and ConfigurationSection.

  • A class named UrlsSection that derives from the ConfigurationSection class. This class is used to access the MyUrls section in the configuration file.

  • A class named UrlsCollection that derives from the ConfigurationElementCollection class. This class is used to access the urls collection in the configuration file.

  • A class named UrlConfigElement that derives from the ConfigurationElement class. This class is used to access the simple element and the members of the urls collection in the configuration file.

To run the example, perform the following steps:

  1. Create a solution that has a console application project and a class library project that is named ConfigurationElement.

  2. Put the three class files in the class library project and put the other files in the console library project.

  3. In both projects set a reference to System.Configuration.

  4. In the console application project set a project reference to the class library project.

<configuration>
	<configSections>
		<section name="MyUrls" type="Samples.AspNet.UrlsSection, ConfigurationElement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
	</configSections>
	<MyUrls name="MyFavorites">
    <simple name="Microsoft1" url="http://www.microsoft1.com" port="1" />
    <urls>
      <clear />
      <add name="Microsoft2" url="http://www.microsoft2.com" port="2" />
      <add name="Contoso" url="http://www.contoso.com" port="8080" />
    </urls>
	</MyUrls>
</configuration>
' Set Assembly name to ConfigurationElement 
' and set Root namespace to Samples.AspNet 
Imports System
Imports System.Configuration
Imports System.Collections

Class TestConfigurationElement
    ' Entry point for console application that reads the  
    ' app.config file and writes to the console the  
    ' URLs in the custom section. 
    Shared Sub Main(ByVal args() As String)
        ' Get the current configuration file. 
        Dim config As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

        ' Get the MyUrls section. 
        Dim myUrlsSection As UrlsSection = _
            config.GetSection("MyUrls")

        If myUrlsSection Is Nothing Then
            Console.WriteLine("Failed to load UrlsSection.")
        Else
            Console.WriteLine("The 'simple' element of app.config:")
            Console.WriteLine("  Name={0} URL={1} Port={2}", _
                myUrlsSection.Simple.Name, _
                myUrlsSection.Simple.Url, _
                myUrlsSection.Simple.Port)
            Console.WriteLine("The urls collection of app.config:")
            Dim i As Integer 
            For i = 0 To myUrlsSection.Urls.Count - 1
                Console.WriteLine("  Name={0} URL={1} Port={2}", _
                i, myUrlsSection.Urls(i).Name, _
                myUrlsSection.Urls(i).Url, _
                myUrlsSection.Urls(i).Port)
            Next i
        End If
        Console.ReadLine()
    End Sub 
End Class
// Set Assembly name to ConfigurationElement 
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    // Entry point for console application that reads the  
    // app.config file and writes to the console the  
    // URLs in the custom section.   
    class TestConfigurationElement
    {
        static void Main(string[] args)
        {
            // Get current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

            // Get the MyUrls section.
            UrlsSection myUrlsSection =
                config.GetSection("MyUrls") as UrlsSection;

            if (myUrlsSection == null)
                Console.WriteLine("Failed to load UrlsSection.");
            else
            {
                Console.WriteLine("The 'simple' element of app.config:");
                Console.WriteLine("  Name={0} URL={1} Port={2}",
                    myUrlsSection.Simple.Name,
                    myUrlsSection.Simple.Url,
                    myUrlsSection.Simple.Port);

                Console.WriteLine("The urls collection of app.config:");
                for (int i = 0; i < myUrlsSection.Urls.Count; i++)
                {
                    Console.WriteLine("  Name={0} URL={1} Port={2}",
                        myUrlsSection.Urls[i].Name,
                        myUrlsSection.Urls[i].Url,
                        myUrlsSection.Urls[i].Port);
                }
            }
            Console.ReadLine();
        }
    }
}
Imports System
Imports System.Configuration
Imports System.Collections

' Define a custom section containing an individual 
' element and a collection of elements. 
Public Class UrlsSection
    Inherits ConfigurationSection

    <ConfigurationProperty("name", _
        DefaultValue:="MyFavorites", _
        IsRequired:=True, _
        IsKey:=False), _
        StringValidator( _
        InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
        MinLength:=1, MaxLength:=60)> _
        Public Property Name() As String 

        Get 
            Return CStr(Me("name"))
        End Get 
        Set(ByVal value As String)
            Me("name") = value
        End Set 
    End Property 

    ' Declare an element (not in a collection) of the type 
    ' UrlConfigElement. In the configuration 
    ' file it corresponds to <simple .... />.
    <ConfigurationProperty("simple")> _
        Public ReadOnly Property Simple() _
        As UrlConfigElement

        Get 
            Dim url As UrlConfigElement = _
                CType(Me("simple"),  _
                UrlConfigElement)
            Return url
        End Get 
    End Property 

    ' Declare a collection element represented  
    ' in the configuration file by the sub-section 
    ' <urls> <add .../> </urls>  
    ' Note: the "IsDefaultCollection = false"  
    ' instructs the .NET Framework to build a nested  
    ' section like <urls> ...</urls>.
    <ConfigurationProperty("urls", _
        IsDefaultCollection:=False)> _
        Public ReadOnly Property Urls() _
        As UrlsCollection

        Get 
            Dim urlsCollection _
                As UrlsCollection = _
                CType(Me("urls"), UrlsCollection)
            Return urlsCollection
        End Get 
    End Property 

    Protected Overrides Sub DeserializeSection( _
        ByVal reader As System.Xml.XmlReader)

        MyBase.DeserializeSection(reader)
        ' Enter your custom processing code here. 
    End Sub 'DeserializeSection

    Protected Overrides Function SerializeSection( _
        ByVal parentElement As ConfigurationElement, _
        ByVal name As String, _
        ByVal saveMode As ConfigurationSaveMode) As String 

        Dim s As String = _
            MyBase.SerializeSection(parentElement, _
            name, saveMode)
        ' Enter your custom processing code here. 
        Return s
    End Function 'SerializeSection
End Class 'UrlsSection 
using System;
using System.Configuration;
using System.Collections;


namespace Samples.AspNet
{
    // Define a custom section containing an individual 
    // element and a collection of elements. 
    public class UrlsSection : ConfigurationSection
    {
        [ConfigurationProperty("name", 
            DefaultValue = "MyFavorites",
            IsRequired = true, 
            IsKey = false)]
        [StringValidator(InvalidCharacters = 
            " ~!@#$%^&*()[]{}/;'\"|\\",
            MinLength = 1, MaxLength = 60)]
        public string Name
        {

            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }

        }

        // Declare an element (not in a collection) of the type 
        // UrlConfigElement. In the configuration 
        // file it corresponds to <simple .... />.
        [ConfigurationProperty("simple")]
        public UrlConfigElement Simple
        {
            get
            {
                UrlConfigElement url =
                (UrlConfigElement)base["simple"];
                return url;
            }
        }

        // Declare a collection element represented  
        // in the configuration file by the sub-section 
        // <urls> <add .../> </urls>  
        // Note: the "IsDefaultCollection = false"  
        // instructs the .NET Framework to build a nested  
        // section like <urls> ...</urls>.
        [ConfigurationProperty("urls",
            IsDefaultCollection = false)]
        public UrlsCollection Urls
        {
            get
            {
                UrlsCollection urlsCollection =
                (UrlsCollection)base["urls"];
                return urlsCollection;
            }
        }


        protected override void DeserializeSection(
            System.Xml.XmlReader reader)
        {
            base.DeserializeSection(reader);
            // You can add custom processing code here.
        }

        protected override string SerializeSection(
            ConfigurationElement parentElement,
            string name, ConfigurationSaveMode saveMode)
        {
            string s =
                base.SerializeSection(parentElement,
                name, saveMode);
            // You can add custom processing code here. 
            return s;
        }

    }
}
Imports System
Imports System.Configuration
Imports System.Collections

Public Class UrlsCollection
    Inherits ConfigurationElementCollection

    Public Sub New()
        ' Add one url to the collection.  This is 
        ' not necessary; could leave the collection  
        ' empty until items are added to it outside 
        ' the constructor. 
        Dim url As UrlConfigElement = _
            CType(CreateNewElement(), UrlConfigElement)
        ' Add the element to the collection.
        Add(url)
    End Sub 'New 

    Public Overrides ReadOnly Property CollectionType() _
        As ConfigurationElementCollectionType

        Get 
            Return ConfigurationElementCollectionType.AddRemoveClearMap
        End Get 
    End Property 

    Protected Overloads Overrides Function CreateNewElement() _
        As ConfigurationElement

        Return New UrlConfigElement()
    End Function 'CreateNewElement

    Protected Overloads Overrides Function CreateNewElement( _
        ByVal elementName As String) _
        As ConfigurationElement

        Return New UrlConfigElement(elementName)
    End Function 'CreateNewElement

    Protected Overrides Function GetElementKey( _
        ByVal element As ConfigurationElement) As [Object]

        Return CType(element, UrlConfigElement).Name
    End Function 'GetElementKey

    Public Shadows Property AddElementName() As String 

        Get 
            Return MyBase.AddElementName
        End Get 

        Set(ByVal value As String)
            MyBase.AddElementName = value
        End Set 
    End Property 

    Public Shadows Property ClearElementName() As String 
        Get 
            Return MyBase.ClearElementName
        End Get 

        Set(ByVal value As String)
            MyBase.ClearElementName = value
        End Set 
    End Property 

    Public Shadows ReadOnly Property RemoveElementName() As String 
        Get 
            Return MyBase.RemoveElementName
        End Get 
    End Property 

    Public Shadows ReadOnly Property Count() As Integer 
        Get 
            Return MyBase.Count
        End Get 
    End Property 

    Default Public Shadows Property Item( _
    ByVal index As Integer) As UrlConfigElement
        Get 
            Return CType(BaseGet(index), UrlConfigElement)
        End Get 

        Set(ByVal value As UrlConfigElement)
            If Not (BaseGet(index) Is Nothing) Then
                BaseRemoveAt(index)
            End If
            BaseAdd(index, value)
        End Set 
    End Property 

    Default Public Shadows ReadOnly Property Item( _
        ByVal Name As String) As UrlConfigElement

        Get 
            Return CType(BaseGet(Name), UrlConfigElement)
        End Get 
    End Property 

    Public Function IndexOf( _
        ByVal url As UrlConfigElement) As Integer 

        Return BaseIndexOf(url)
    End Function 'IndexOf

    Public Sub Add(ByVal url As UrlConfigElement)
        BaseAdd(url)
        ' Add custom code here. 
    End Sub 'Add

    Protected Overrides Sub BaseAdd( _
    ByVal element As ConfigurationElement)
        BaseAdd(element, False)
        ' Add custom code here. 
    End Sub 'BaseAdd

    Public Overloads Sub Remove( _
        ByVal url As UrlConfigElement)

        If BaseIndexOf(url) >= 0 Then
            BaseRemove(url.Name)
        End If 
    End Sub 'Remove

    Public Sub RemoveAt(ByVal index As Integer)
        BaseRemoveAt(index)
    End Sub 'RemoveAt

    Public Overloads Sub Remove(ByVal name As String)
        BaseRemove(name)
    End Sub 'Remove    

    Public Sub Clear()
        BaseClear()
    End Sub 'Clear ' 
End Class 'UrlsCollection
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    public class UrlsCollection : ConfigurationElementCollection
    {
        public UrlsCollection()
        {
            // Add one url to the collection.  This is 
            // not necessary; could leave the collection  
            // empty until items are added to it outside 
            // the constructor.
            UrlConfigElement url = 
                (UrlConfigElement)CreateNewElement();
            Add(url);
        }

        public override 
            ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return 

                    ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override 
            ConfigurationElement CreateNewElement()
        {
            return new UrlConfigElement();
        }


        protected override 
            ConfigurationElement CreateNewElement(
            string elementName)
        {
            return new UrlConfigElement(elementName);
        }


        protected override Object 
            GetElementKey(ConfigurationElement element)
        {
            return ((UrlConfigElement)element).Name;
        }


        public new string AddElementName
        {
            get
            { return base.AddElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string ClearElementName
        {
            get
            { return base.ClearElementName; }

            set
            { base.ClearElementName = value; }

        }

        public new string RemoveElementName
        {
            get
            { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }


        public UrlConfigElement this[int index]
        {
            get
            {
                return (UrlConfigElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public UrlConfigElement this[string Name]
        {
            get
            {
                return (UrlConfigElement)BaseGet(Name);
            }
        }

        public int IndexOf(UrlConfigElement url)
        {
            return BaseIndexOf(url);
        }

        public void Add(UrlConfigElement url)
        {
            BaseAdd(url);
            // Add custom code here.
        }

        protected override void 
            BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
            // Add custom code here.
        }

        public void Remove(UrlConfigElement url)
        {
            if (BaseIndexOf(url) >= 0)
                BaseRemove(url.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
            // Add custom code here.
        }
    }
}
Imports System
Imports System.Configuration
Imports System.Collections

Public Class UrlConfigElement
    Inherits ConfigurationElement

    ' Constructor allowing name, url, and port to be specified. 
    Public Sub New(ByVal newName As String, _
        ByVal newUrl As String, _
        ByVal newPort As Integer)

        Name = newName
        Url = newUrl
        Port = newPort

    End Sub 'New 

    ' Default constructor, will use default values as defined 
    Public Sub New()

    End Sub 'New 


    ' Constructor allowing name to be specified, will take the 
    ' default values for url and port. 
    Public Sub New(ByVal elementName As String)
        Name = elementName

    End Sub 'New


    <ConfigurationProperty("name", _
        DefaultValue:="Microsoft", _
        IsRequired:=True, _
        IsKey:=True)> _
        Public Property Name() As String 

        Get 
            Return CStr(Me("name"))
        End Get 
        Set(ByVal value As String)
            Me("name") = value
        End Set 
    End Property


    <ConfigurationProperty("url", _
        DefaultValue:="http://www.microsoft.com", _
        IsRequired:=True), _
        RegexStringValidator("\w+:\/\/[\w.]+\S*")> _
        Public Property Url() As String 

        Get 
            Return CStr(Me("url"))
        End Get 
        Set(ByVal value As String)
            Me("url") = value
        End Set 
    End Property


    <ConfigurationProperty("port", _
        DefaultValue:=0, _
        IsRequired:=False), _
        IntegerValidator(MinValue:=0, _
        MaxValue:=8080, ExcludeRange:=False)> _
        Public Property Port() As Integer 

        Get 
            Return Fix(Me("port"))
        End Get 
        Set(ByVal value As Integer)
            Me("port") = value
        End Set 
    End Property 


    Protected Overrides Sub DeserializeElement(ByVal reader _
        As System.Xml.XmlReader, _
        ByVal serializeCollectionKey As Boolean)

        MyBase.DeserializeElement(reader, _
            serializeCollectionKey)
        ' Enter your custom processing code here. 
    End Sub 'DeserializeElement

    Protected Overrides Function SerializeElement(ByVal writer _
        As System.Xml.XmlWriter, _
        ByVal serializeCollectionKey As Boolean) As Boolean 

        Dim ret As Boolean = _
            MyBase.SerializeElement(writer, serializeCollectionKey)
        ' Enter your custom processing code here. 
        Return ret
    End Function 'SerializeElement

    Protected Overrides Function IsModified() As Boolean 
        Dim ret As Boolean = MyBase.IsModified()
        ' Enter your custom processing code here. 
        Return ret

    End Function 'IsModified
End Class 'UrlConfigElement 
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    public class UrlConfigElement : ConfigurationElement
    {
        // Constructor allowing name, url, and port to be specified. 
        public UrlConfigElement(String newName,
            String newUrl, int newPort)
        {
            Name = newName;
            Url = newUrl;
            Port = newPort;
        }

        // Default constructor, will use default values as defined 
        // below. 
        public UrlConfigElement()
        {
        }

        // Constructor allowing name to be specified, will take the 
        // default values for url and port. 
        public UrlConfigElement(string elementName)
        {
            Name = elementName;
        }

        [ConfigurationProperty("name", 
            DefaultValue = "Microsoft",
            IsRequired = true, 
            IsKey = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("url",
            DefaultValue = "http://www.microsoft.com",
            IsRequired = true)]
        [RegexStringValidator(@"\w+:\/\/[\w.]+\S*")]
        public string Url
        {
            get
            {
                return (string)this["url"];
            }
            set
            {
                this["url"] = value;
            }
        }

        [ConfigurationProperty("port",
            DefaultValue = (int)0,
            IsRequired = false)]
        [IntegerValidator(MinValue = 0,
            MaxValue = 8080, ExcludeRange = false)]
        public int Port
        {
            get
            {
                return (int)this["port"];
            }
            set
            {
                this["port"] = value;
            }
        }

        protected override void DeserializeElement(
           System.Xml.XmlReader reader, 
            bool serializeCollectionKey)
        {
            base.DeserializeElement(reader, 
                serializeCollectionKey);
            // You can your custom processing code here.
        }


        protected override bool SerializeElement(
            System.Xml.XmlWriter writer, 
            bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer, 
                serializeCollectionKey);
            // You can enter your custom processing code here. 
            return ret;

        }


        protected override bool IsModified()
        {
            bool ret = base.IsModified();
            // You can enter your custom processing code here. 
            return ret;
        }
    }
}
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Inheritance Hierarchy
SystemObject
  System.ConfigurationConfigurationElement
     System.ConfigurationConfigurationElementCollection
     System.ConfigurationConfigurationSection
     System.ConfigurationConnectionStringSettings
     System.ConfigurationIdnElement
     System.ConfigurationIriParsingElement
     System.ConfigurationKeyValueConfigurationElement
     System.ConfigurationNameValueConfigurationElement
     System.ConfigurationProtectedProviderSettings
     System.ConfigurationProviderSettings
     System.ConfigurationSchemeSettingElement
     System.ConfigurationSettingElement
     System.ConfigurationSettingValueElement
     System.Data.Services.ConfigurationDataServicesReplaceFunctionFeature
     System.IdentityModel.ConfigurationAudienceUriElement
     System.IdentityModel.ConfigurationConfigurationElementInterceptor
     System.IdentityModel.ConfigurationIdentityConfigurationElement
     System.IdentityModel.ConfigurationIdentityModelCachesElement
     System.IdentityModel.ConfigurationSecurityTokenHandlerConfigurationElement
     System.IdentityModel.ConfigurationTokenReplayDetectionElement
     System.IdentityModel.ConfigurationX509CertificateValidationElement
     System.IdentityModel.ServicesChunkedCookieHandlerElement
     System.IdentityModel.Services.ConfigurationFederationConfigurationElement
     System.IdentityModel.Services.ConfigurationWSFederationElement
     System.IdentityModel.ServicesCookieHandlerElement
     System.IdentityModel.ServicesServiceCertificateElement
     System.Net.ConfigurationAuthenticationModuleElement
     System.Net.ConfigurationBypassElement
     System.Net.ConfigurationConnectionManagementElement
     System.Net.ConfigurationFtpCachePolicyElement
     System.Net.ConfigurationHttpCachePolicyElement
     System.Net.ConfigurationHttpListenerElement
     System.Net.ConfigurationHttpListenerTimeoutsElement
     System.Net.ConfigurationHttpWebRequestElement
     System.Net.ConfigurationIpv6Element
     System.Net.ConfigurationModuleElement
     System.Net.ConfigurationPerformanceCountersElement
     System.Net.ConfigurationProxyElement
     System.Net.ConfigurationServicePointManagerElement
     System.Net.ConfigurationSmtpNetworkElement
     System.Net.ConfigurationSmtpSpecifiedPickupDirectoryElement
     System.Net.ConfigurationSocketElement
     System.Net.ConfigurationWebProxyScriptElement
     System.Net.ConfigurationWebRequestModuleElement
     System.Net.ConfigurationWebUtilityElement
     System.Runtime.Caching.ConfigurationMemoryCacheElement
     System.Runtime.Serialization.ConfigurationDeclaredTypeElement
     System.Runtime.Serialization.ConfigurationParameterElement
     System.Runtime.Serialization.ConfigurationTypeElement
     System.Security.Authentication.ExtendedProtection.ConfigurationExtendedProtectionPolicyElement
     System.Security.Authentication.ExtendedProtection.ConfigurationServiceNameElement
     System.ServiceModel.Activation.ConfigurationSecurityIdentifierElement
     System.ServiceModel.Activities.ConfigurationChannelSettingsElement
     System.ServiceModel.Activities.ConfigurationFactorySettingsElement
     System.ServiceModel.Activities.Tracking.ConfigurationTrackingConfigurationElement
     System.ServiceModel.ConfigurationAllowedAudienceUriElement
     System.ServiceModel.ConfigurationAuthorizationPolicyTypeElement
     System.ServiceModel.ConfigurationBaseAddressElement
     System.ServiceModel.ConfigurationBaseAddressPrefixFilterElement
     System.ServiceModel.ConfigurationBindingCollectionElement
     System.ServiceModel.ConfigurationCertificateElement
     System.ServiceModel.ConfigurationCertificateReferenceElement
     System.ServiceModel.ConfigurationChannelEndpointElement
     System.ServiceModel.ConfigurationClaimTypeElement
     System.ServiceModel.ConfigurationComContractElement
     System.ServiceModel.ConfigurationComMethodElement
     System.ServiceModel.ConfigurationComPersistableTypeElement
     System.ServiceModel.ConfigurationComUdtElement
     System.ServiceModel.ConfigurationDefaultPortElement
     System.ServiceModel.ConfigurationDelegatingHandlerElement
     System.ServiceModel.ConfigurationDnsElement
     System.ServiceModel.ConfigurationEndpointCollectionElement
     System.ServiceModel.ConfigurationEndToEndTracingElement
     System.ServiceModel.ConfigurationExtensionElement
     System.ServiceModel.ConfigurationHostElement
     System.ServiceModel.ConfigurationHostTimeoutsElement
     System.ServiceModel.ConfigurationHttpDigestClientElement
     System.ServiceModel.ConfigurationHttpMessageHandlerFactoryElement
     System.ServiceModel.ConfigurationIdentityElement
     System.ServiceModel.ConfigurationIssuedTokenClientBehaviorsElement
     System.ServiceModel.ConfigurationIssuedTokenClientElement
     System.ServiceModel.ConfigurationIssuedTokenServiceElement
     System.ServiceModel.ConfigurationMessageLoggingElement
     System.ServiceModel.ConfigurationMetadataElement
     System.ServiceModel.ConfigurationPeerCredentialElement
     System.ServiceModel.ConfigurationPolicyImporterElement
     System.ServiceModel.ConfigurationProtocolMappingElement
     System.ServiceModel.ConfigurationRsaElement
     System.ServiceModel.ConfigurationSecureConversationServiceElement
     System.ServiceModel.ConfigurationServiceActivationElement
     System.ServiceModel.ConfigurationServiceElement
     System.ServiceModel.ConfigurationServiceEndpointElement
     System.ServiceModel.ConfigurationServiceModelConfigurationElement
     System.ServiceModel.ConfigurationServiceModelExtensionCollectionElementTServiceModelExtensionElement
     System.ServiceModel.ConfigurationServicePrincipalNameElement
     System.ServiceModel.ConfigurationStandardEndpointElement
     System.ServiceModel.ConfigurationTransportConfigurationTypeElement
     System.ServiceModel.ConfigurationUserNameServiceElement
     System.ServiceModel.ConfigurationUserPrincipalNameElement
     System.ServiceModel.ConfigurationWindowsClientElement
     System.ServiceModel.ConfigurationWindowsServiceElement
     System.ServiceModel.ConfigurationWsdlImporterElement
     System.ServiceModel.ConfigurationX509CertificateTrustedIssuerElement
     System.ServiceModel.ConfigurationX509ClientCertificateAuthenticationElement
     System.ServiceModel.ConfigurationX509ClientCertificateCredentialsElement
     System.ServiceModel.ConfigurationX509DefaultServiceCertificateElement
     System.ServiceModel.ConfigurationX509InitiatorCertificateClientElement
     System.ServiceModel.ConfigurationX509InitiatorCertificateServiceElement
     System.ServiceModel.ConfigurationX509PeerCertificateAuthenticationElement
     System.ServiceModel.ConfigurationX509PeerCertificateElement
     System.ServiceModel.ConfigurationX509RecipientCertificateClientElement
     System.ServiceModel.ConfigurationX509RecipientCertificateServiceElement
     System.ServiceModel.ConfigurationX509ScopedServiceCertificateElement
     System.ServiceModel.ConfigurationX509ServiceCertificateAuthenticationElement
     System.ServiceModel.ConfigurationXmlElementElement
     System.ServiceModel.ConfigurationXPathMessageFilterElement
     System.ServiceModel.Discovery.ConfigurationContractTypeNameElement
     System.ServiceModel.Discovery.ConfigurationDiscoveryClientSettingsElement
     System.ServiceModel.Discovery.ConfigurationFindCriteriaElement
     System.ServiceModel.Discovery.ConfigurationScopeElement
     System.ServiceModel.Discovery.ConfigurationUdpTransportSettingsElement
     System.ServiceModel.Routing.ConfigurationBackupEndpointElement
     System.ServiceModel.Routing.ConfigurationFilterElement
     System.ServiceModel.Routing.ConfigurationFilterTableEntryElement
     System.ServiceModel.Routing.ConfigurationNamespaceElement
     System.Web.ConfigurationAssemblyInfo
     System.Web.ConfigurationAuthorizationRule
     System.Web.ConfigurationBufferModeSettings
     System.Web.ConfigurationBuildProvider
     System.Web.ConfigurationClientTarget
     System.Web.ConfigurationCodeSubDirectory
     System.Web.ConfigurationCompiler
     System.Web.ConfigurationConverter
     System.Web.ConfigurationCustomError
     System.Web.ConfigurationEventMappingSettings
     System.Web.ConfigurationExpressionBuilder
     System.Web.ConfigurationFolderLevelBuildProvider
     System.Web.ConfigurationFormsAuthenticationConfiguration
     System.Web.ConfigurationFormsAuthenticationCredentials
     System.Web.ConfigurationFormsAuthenticationUser
     System.Web.ConfigurationFullTrustAssembly
     System.Web.ConfigurationHttpHandlerAction
     System.Web.ConfigurationHttpModuleAction
     System.Web.ConfigurationIgnoreDeviceFilterElement
     System.Web.ConfigurationNamespaceInfo
     System.Web.ConfigurationOutputCacheProfile
     System.Web.ConfigurationPartialTrustVisibleAssembly
     System.Web.ConfigurationPassportAuthentication
     System.Web.ConfigurationProfileGroupSettings
     System.Web.ConfigurationProfilePropertySettings
     System.Web.ConfigurationProfileSettings
     System.Web.ConfigurationProtocolElement
     System.Web.ConfigurationRuleSettings
     System.Web.ConfigurationSqlCacheDependencyDatabase
     System.Web.ConfigurationTagMapInfo
     System.Web.ConfigurationTagPrefixInfo
     System.Web.ConfigurationTransformerInfo
     System.Web.ConfigurationTrustLevel
     System.Web.ConfigurationUrlMapping
     System.Web.ConfigurationWebPartsPersonalization
     System.Web.ConfigurationWebPartsPersonalizationAuthorization
     System.Web.MobileDeviceFilterElement
     System.Web.Services.ConfigurationDiagnosticsElement
     System.Web.Services.ConfigurationProtocolElement
     System.Web.Services.ConfigurationSoapEnvelopeProcessingElement
     System.Web.Services.ConfigurationSoapExtensionTypeElement
     System.Web.Services.ConfigurationTypeElement
     System.Web.Services.ConfigurationWsdlHelpGeneratorElement
     System.Web.Services.ConfigurationWsiProfilesElement
     System.Web.UI.MobileControlsControlElement
     System.Web.UI.MobileControlsDeviceElement
     System.Workflow.Runtime.ConfigurationWorkflowRuntimeServiceElement
     System.Xaml.Hosting.ConfigurationHandlerElement
     System.Xml.Serialization.ConfigurationSchemaImporterExtensionElement