ConfigurationElementCollection-Klasse
Aktualisiert: November 2007
Stellt ein Konfigurationselement dar, das eine Auflistung der untergeordneten Elemente enthält.
Assembly: System.Configuration (in System.Configuration.dll)
public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable
public abstract class ConfigurationElementCollection extends ConfigurationElement implements ICollection, IEnumerable
public abstract class ConfigurationElementCollection extends ConfigurationElement implements ICollection, IEnumerable
Die ConfigurationElementCollection stellt innerhalb einer Konfigurationsdatei eine Auflistung der Elemente dar.
Hinweis: |
|---|
Ein Element innerhalb einer Konfigurationsdatei verweist auf ein grundlegendes XML-Element oder einen Abschnitt. Ein einfaches Element ist ein XML-Tag mit zugehörigen Attributen, sofern vorhanden. Ein einfaches Element bildet einen Abschnitt. Komplexe Abschnitte können ein oder mehrere einfache Elemente, eine Auflistung von Elementen und andere Abschnitte enthalten. |
Sie verwenden die ConfigurationElementCollection, um mit einer Auflistung der ConfigurationElement-Objekte zu arbeiten. Implementieren Sie diese Klasse, um einem ConfigurationSection Auflistungen benutzerdefinierter ConfigurationElement-Elemente hinzuzufügen.
Hinweise zur Implementierung:Sie können ein programmgesteuertes oder deklaratives (attributiertes) Codierungsmodell zum Erstellen eines benutzerdefinierten Konfigurationselements verwenden.
Für das programmgesteuerte Modell ist es erforderlich, dass Sie für jedes Elementattribut eine Eigenschaft erstellen, um seinen Wert abzurufen und festzulegen und ihn der internen Eigenschaftensammlung der zugrunde liegenden ConfigurationElement-Basisklasse hinzufügen.
Mit dem deklarativen Modell, das auch attributiertes Modell genannt wird, können Sie ein Elementattribut durch die Verwendung einer Eigenschaft und ihre Konfiguration mit Attributen definieren. Diese Attribute geben dem ASP.NET-Konfigurationssystem Anweisungen zu den Eigenschaftentypen und ihren Standardwerten. ASP.NET kann Reflektion verwenden, um diese Informationen zu erhalten, und kann dann die Elementeigenschaftenobjekte erstellen und die erforderliche Initialisierung ausführen.
Im folgenden Codebeispiel wird veranschaulicht, wie eine benutzerdefinierte ConfigurationElementCollection implementiert wird. Beispiele für zugehörige benutzerdefinierte Typen finden Sie unter ConfigurationSection und ConfigurationElement.
using System; using System.Configuration; using System.Collections; namespace Samples.AspNet { // Define the UrlsCollection that contains // UrlsConfigElement elements. public class UrlsCollection : ConfigurationElementCollection { public UrlsCollection() { UrlConfigElement url = (UrlConfigElement)CreateNewElement(); // Add the element to the collection. 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.AddElementName = 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. } } }
Der folgende Konfigurationsauszug wurde im vorherigen Beispiel verwendet.
<?xml version="1.0" encoding="utf-8"?>
<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 lockAllElementsExcept="urls">
<internal
name="Microsoft" url="http://www.microsoft.com" port="0" />
<urls>
<clear />
<add
name="Microsoft" url="http://www.microsoft.com" port="0"
lockAllAttributesExcept="port" />
<add
name="Contoso" url="http://www.contoso.com/" port="8080"
lockAllAttributesExcept="port" lockItem="true" />
</urls>
</MyUrls>
</configuration>
System.Configuration.ConfigurationElement
System.Configuration.ConfigurationElementCollection
System.Configuration.ConnectionStringSettingsCollection
System.Configuration.KeyValueConfigurationCollection
System.Configuration.NameValueConfigurationCollection
System.Configuration.ProviderSettingsCollection
System.Configuration.SettingElementCollection
System.Net.Configuration.AuthenticationModuleElementCollection
System.Net.Configuration.BypassElementCollection
System.Net.Configuration.ConnectionManagementElementCollection
System.Net.Configuration.WebRequestModuleElementCollection
System.Runtime.Serialization.Configuration.DeclaredTypeElementCollection
System.Runtime.Serialization.Configuration.ParameterElementCollection
System.Runtime.Serialization.Configuration.TypeElementCollection
System.ServiceModel.Configuration.ServiceModelConfigurationElementCollection<ConfigurationElementType>
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.FormsAuthenticationUserCollection
System.Web.Configuration.HttpHandlerActionCollection
System.Web.Configuration.HttpModuleActionCollection
System.Web.Configuration.NamespaceCollection
System.Web.Configuration.OutputCacheProfileCollection
System.Web.Configuration.ProfileGroupSettingsCollection
System.Web.Configuration.ProfilePropertySettingsCollection
System.Web.Configuration.ProfileSettingsCollection
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.Xml.Serialization.Configuration.SchemaImporterExtensionElementCollection
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Hinweis: