2 out of 14 rated this helpful - Rate this topic

ConfigurationElementCollection Class

Represents a configuration element containing a collection of child elements.

System.Object
  System.Configuration.ConfigurationElement
    System.Configuration.ConfigurationElementCollection
      More...

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
public abstract class ConfigurationElementCollection : ConfigurationElement, 
	ICollection, IEnumerable

The ConfigurationElementCollection type exposes the following members.

  Name Description
Protected method ConfigurationElementCollection() Initializes a new instance of the ConfigurationElementCollection class.
Protected method ConfigurationElementCollection(IComparer) Creates a new instance of the ConfigurationElementCollection class.
Top
  Name Description
Protected property AddElementName Gets or sets the name of the ConfigurationElement to associate with the add operation in the ConfigurationElementCollection when overridden in a derived class.
Protected property ClearElementName Gets or sets the name for the ConfigurationElement to associate with the clear operation in the ConfigurationElementCollection when overridden in a derived class.
Public property CollectionType Gets the type of the ConfigurationElementCollection.
Public property Count Gets the number of elements in the collection.
Public property CurrentConfiguration Gets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to. (Inherited from ConfigurationElement.)
Public property ElementInformation Gets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected property ElementName Gets the name used to identify this collection of elements in the configuration file when overridden in a derived class.
Protected property ElementProperty Gets the ConfigurationElementProperty object that represents the ConfigurationElement object itself. (Inherited from ConfigurationElement.)
Public property EmitClear Gets or sets a value that specifies whether the collection has been cleared.
Protected property EvaluationContext Gets the ContextInformation object for the ConfigurationElement object. (Inherited from ConfigurationElement.)
Public property IsSynchronized Gets a value indicating whether access to the collection is synchronized (thread safe).
Protected property Item[ConfigurationProperty] Gets or sets a property or attribute of this configuration element. (Inherited from ConfigurationElement.)
Protected property Item[String] Gets or sets a property, attribute, or child element of this configuration element. (Inherited from ConfigurationElement.)
Public property LockAllAttributesExcept Gets the collection of locked attributes. (Inherited from ConfigurationElement.)
Public property LockAllElementsExcept Gets the collection of locked elements. (Inherited from ConfigurationElement.)
Public property LockAttributes Gets the collection of locked attributes (Inherited from ConfigurationElement.)
Public property LockElements Gets the collection of locked elements. (Inherited from ConfigurationElement.)
Public property LockItem Gets or sets a value indicating whether the element is locked. (Inherited from ConfigurationElement.)
Protected property Properties Gets the collection of properties. (Inherited from ConfigurationElement.)
Protected property RemoveElementName Gets or sets the name of the ConfigurationElement to associate with the remove operation in the ConfigurationElementCollection when overridden in a derived class.
Public property SyncRoot Gets an object used to synchronize access to the ConfigurationElementCollection.
Protected property ThrowOnDuplicate Gets a value indicating whether an attempt to add a duplicate ConfigurationElement to the ConfigurationElementCollection will cause an exception to be thrown.
Top
  Name Description
Protected method BaseAdd(ConfigurationElement) Adds a configuration element to the ConfigurationElementCollection.
Protected method BaseAdd(ConfigurationElement, Boolean) Adds a configuration element to the configuration element collection.
Protected method BaseAdd(Int32, ConfigurationElement) Adds a configuration element to the configuration element collection.
Protected method BaseClear Removes all configuration element objects from the collection.
Protected method BaseGet(Int32) Gets the configuration element at the specified index location.
Protected method BaseGet(Object) Returns the configuration element with the specified key.
Protected method BaseGetAllKeys Returns an array of the keys for all of the configuration elements contained in the ConfigurationElementCollection.
Protected method BaseGetKey Gets the key for the ConfigurationElement at the specified index location.
Protected method BaseIndexOf The index of the specified ConfigurationElement.
Protected method BaseIsRemoved Gets a value indicating whether the ConfigurationElement with the specified key has been removed from the ConfigurationElementCollection.
Protected method BaseRemove Removes a ConfigurationElement from the collection.
Protected method BaseRemoveAt Removes the ConfigurationElement at the specified index location.
Public method CopyTo Copies the contents of the ConfigurationElementCollection to an array.
Protected method CreateNewElement() When overridden in a derived class, creates a new ConfigurationElement.
Protected method CreateNewElement(String) Creates a new ConfigurationElement when overridden in a derived class.
Protected method DeserializeElement Reads XML from the configuration file. (Inherited from ConfigurationElement.)
Public method Equals Compares the ConfigurationElementCollection to the specified object. (Overrides ConfigurationElement.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected method GetElementKey Gets the element key for a specified configuration element when overridden in a derived class.
Public method GetEnumerator Infrastructure. Gets an IEnumerator which is used to iterate through the ConfigurationElementCollection.
Public method GetHashCode Gets a unique value representing the ConfigurationElementCollection instance. (Overrides ConfigurationElement.GetHashCode().)
Protected method GetTransformedAssemblyString Returns the transformed version of the specified assembly name. (Inherited from ConfigurationElement.)
Protected method GetTransformedTypeString Returns the transformed version of the specified type name. (Inherited from ConfigurationElement.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Init Sets the ConfigurationElement object to its initial state. (Inherited from ConfigurationElement.)
Protected method InitializeDefault Used to initialize a default set of values for the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected method IsElementName Indicates whether the specified ConfigurationElement exists in the ConfigurationElementCollection.
Protected method IsElementRemovable Gets a value indicating whether the specified ConfigurationElement can be removed from the ConfigurationElementCollection.
Protected method IsModified Indicates whether this ConfigurationElementCollection has been modified since it was last saved or loaded when overridden in a derived class. (Overrides ConfigurationElement.IsModified().)
Public method IsReadOnly Gets a value indicating whether the ConfigurationElementCollection object is read only. (Overrides ConfigurationElement.IsReadOnly().)
Protected method ListErrors Adds the invalid-property errors in this ConfigurationElement object, and in all subelements, to the passed list. (Inherited from ConfigurationElement.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnDeserializeUnrecognizedAttribute Gets a value indicating whether an unknown attribute is encountered during deserialization. (Inherited from ConfigurationElement.)
Protected method OnDeserializeUnrecognizedElement Causes the configuration system to throw an exception. (Overrides ConfigurationElement.OnDeserializeUnrecognizedElement(String, XmlReader).)
Protected method OnRequiredPropertyNotFound Throws an exception when a required property is not found. (Inherited from ConfigurationElement.)
Protected method PostDeserialize Called after deserialization. (Inherited from ConfigurationElement.)
Protected method PreSerialize Called before serialization. (Inherited from ConfigurationElement.)
Protected method Reset Resets the ConfigurationElementCollection to its unmodified state when overridden in a derived class. (Overrides ConfigurationElement.Reset(ConfigurationElement).)
Protected method ResetModified Resets the value of the IsModified property to false when overridden in a derived class. (Overrides ConfigurationElement.ResetModified().)
Protected method SerializeElement Writes the configuration data to an XML element in the configuration file when overridden in a derived class. (Overrides ConfigurationElement.SerializeElement(XmlWriter, Boolean).)
Protected method SerializeToXmlElement Writes the outer tags of this configuration element to the configuration file when implemented in a derived class. (Inherited from ConfigurationElement.)
Protected method SetPropertyValue Sets a property to the specified value. (Inherited from ConfigurationElement.)
Protected method SetReadOnly Infrastructure. Sets the IsReadOnly property for the ConfigurationElementCollection object and for all sub-elements. (Overrides ConfigurationElement.SetReadOnly().)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Protected method Unmerge Infrastructure. Reverses the effect of merging configuration information from different levels of the configuration hierarchy (Overrides ConfigurationElement.Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode).)
Top
  Name Description
Public Extension Method AsParallel Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension Method AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method Cast<TResult> Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  Name Description
Explicit interface implemetation Private method ICollection.CopyTo Copies the ConfigurationElementCollection to an array.
Top

The ConfigurationElementCollection represents a collection of elements within a configuration file.

Note Note

An element within a configuration file refers to a basic XML element or a section. A simple element is an XML tag with related attributes, if any. A simple element constitutes a section. Complex sections can contain one or more simple elements, a collection of elements, and other sections.

You use the ConfigurationElementCollection to work with a collection of ConfigurationElement objects. Implement this class to add collections of custom ConfigurationElement elements to a ConfigurationSection.

Notes to Implementers

You can use 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 and set its value, and that you add it to the internal property bag of the underlying ConfigurationElement base class.

The declarative model, also referred to as the attributed model, allows you to define an element attribute by using a property and configuring it with attributes. These attributes instruct the ASP.NET configuration system about the property types and their default values. ASP.NET can use reflection to obtain this information and then create the element property objects and perform the required initialization.

The following example shows how to use the ConfigurationCollectionElement.

The first example consists of three classes: UrlsSection, UrlsCollection and UrlConfigElement.The UrlsSection class uses the ConfigurationCollectionAttribute to define a custom configuration section. This section contains a URL collection (defined by the UrlsCollection class) of URL elements (defined by the UrlConfigElement class).

This second code example uses the classes specified before. You combine these two examples in a console application project.

When you run the console application, an instance of the UrlsSection class is created and the following configuration elements are generated in the application configuration file:

<configuration>
    <configSections>
        <section name="MyUrls" type="UrlsSection, 
          ConfigurationElementCollection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </configSections>
    <MyUrls>
        <urls>
           <add name="Contoso" url="http://www.contoso.com" port="4040 />
        </urls>
    </MyUrls>
</configuration

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

Expanded scope of code example.

Customer feedback.

System.Object
  System.Configuration.ConfigurationElement
    System.Configuration.ConfigurationElementCollection
      System.Configuration.ConnectionStringSettingsCollection
      System.Configuration.KeyValueConfigurationCollection
      System.Configuration.NameValueConfigurationCollection
      System.Configuration.ProviderSettingsCollection
      System.Configuration.SchemeSettingElementCollection
      System.Configuration.SettingElementCollection
      System.Net.Configuration.AuthenticationModuleElementCollection
      System.Net.Configuration.BypassElementCollection
      System.Net.Configuration.ConnectionManagementElementCollection
      System.Net.Configuration.WebRequestModuleElementCollection
      System.Runtime.Caching.Configuration.MemoryCacheSettingsCollection
      System.Runtime.Serialization.Configuration.DeclaredTypeElementCollection
      System.Runtime.Serialization.Configuration.ParameterElementCollection
      System.Runtime.Serialization.Configuration.TypeElementCollection
      System.Security.Authentication.ExtendedProtection.Configuration.ServiceNameElementCollection
      System.ServiceModel.Activities.Tracking.Configuration.TrackingConfigurationCollection<TConfigurationElement>
      System.ServiceModel.Configuration.ServiceModelConfigurationElementCollection<ConfigurationElementType>
      System.ServiceModel.Routing.Configuration.BackupEndpointCollection
      System.ServiceModel.Routing.Configuration.BackupListCollection
      System.ServiceModel.Routing.Configuration.FilterElementCollection
      System.ServiceModel.Routing.Configuration.FilterTableCollection
      System.ServiceModel.Routing.Configuration.FilterTableEntryCollection
      System.ServiceModel.Routing.Configuration.NamespaceElementCollection
      System.Web.Configuration.AssemblyCollection
      System.Web.Configuration.AuthorizationRuleCollection
      System.Web.Configuration.BufferModesCollection
      System.Web.Configuration.BuildProviderCollection
      System.Web.Configuration.ClientTargetCollection
      System.Web.Configuration.CodeSubDirectoriesCollection
      System.Web.Configuration.CompilerCollection
      System.Web.Configuration.ConvertersCollection
      System.Web.Configuration.CustomErrorCollection
      System.Web.Configuration.EventMappingSettingsCollection
      System.Web.Configuration.ExpressionBuilderCollection
      System.Web.Configuration.FolderLevelBuildProviderCollection
      System.Web.Configuration.FormsAuthenticationUserCollection
      System.Web.Configuration.FullTrustAssemblyCollection
      System.Web.Configuration.HttpHandlerActionCollection
      System.Web.Configuration.HttpModuleActionCollection
      System.Web.Configuration.IgnoreDeviceFilterElementCollection
      System.Web.Configuration.NamespaceCollection
      System.Web.Configuration.OutputCacheProfileCollection
      System.Web.Configuration.PartialTrustVisibleAssemblyCollection
      System.Web.Configuration.ProfileGroupSettingsCollection
      System.Web.Configuration.ProfilePropertySettingsCollection
      System.Web.Configuration.ProfileSettingsCollection
      System.Web.Configuration.ProtocolCollection
      System.Web.Configuration.RuleSettingsCollection
      System.Web.Configuration.SqlCacheDependencyDatabaseCollection
      System.Web.Configuration.TagMapCollection
      System.Web.Configuration.TagPrefixCollection
      System.Web.Configuration.TransformerInfoCollection
      System.Web.Configuration.TrustLevelCollection
      System.Web.Configuration.UrlMappingCollection
      System.Web.Mobile.DeviceFilterElementCollection
      System.Web.Services.Configuration.ProtocolElementCollection
      System.Web.Services.Configuration.SoapExtensionTypeElementCollection
      System.Web.Services.Configuration.TypeElementCollection
      System.Web.Services.Configuration.WsiProfilesElementCollection
      System.Web.UI.MobileControls.ControlElementCollection
      System.Web.UI.MobileControls.DeviceElementCollection
      System.Workflow.Runtime.Configuration.WorkflowRuntimeServiceElementCollection
      System.Xaml.Hosting.Configuration.HandlerElementCollection
      System.Xml.Serialization.Configuration.SchemaImporterExtensionElementCollection
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Shockingly bad explaination
This document is here just to tick a box, without spending any time on it. $0MS is getting a reputation for this kind of thing.$0 $0Where is the real documentation?$0 $0
Poor
Agreed with previous poster - there should be code examples here...
  • 10/20/2011
  • SRL
Where is Example?
I need a preferably C# or VB.net  code example for this.
Where's the code in the example?
Uh, I can see the XML for the example, but where's the code to go with it? $0$0 $0 $0vcsjones: If you look at previous versions of the .NET Framework, like 3.0, it has better code samples. Just change the version up at the top.$0