ConfigurationElementCollection クラス
アセンブリ: System.Configuration (system.configuration.dll 内)

Public MustInherit Class ConfigurationElementCollection Inherits ConfigurationElement Implements ICollection, IEnumerable
public abstract class ConfigurationElementCollection : ConfigurationElement, ICollection, IEnumerable
public ref class ConfigurationElementCollection abstract : public ConfigurationElement, ICollection, IEnumerable

ConfigurationElementCollection は、構成ファイル内の要素のコレクションを表します。
![]() |
---|
構成ファイル内の要素とは、基本 XML 要素またはセクションのことです。単純要素は、関連する属性を持つ XML タグです (属性が存在する場合)。単純要素はセクションを構成します。複雑なセクションには、1 つ以上の単純要素、要素のコレクション、および他のセクションを含めることができます。 |
ConfigurationElementCollection を使用して、ConfigurationElement オブジェクトのコレクションを処理します。このクラスを実装し、カスタムの ConfigurationElement 要素のコレクションを ConfigurationSection に追加します。
実装時の注意 プログラム コーディング モデルまたは宣言 (属性付き) コーディング モデルを使用して、カスタム構成要素を作成できます。 プログラム モデルでは、要素の属性ごとに、値を取得および設定するプロパティを作成し、その値を基になる ConfigurationElement 基本クラスの内部プロパティ バッグに追加する必要があります。 宣言モデル (属性付きモデルとも呼ばれます) では、プロパティを使用して属性でそのプロパティを構成することによって、要素の属性を定義できます。これらの属性は、プロパティの型と既定値について、ASP.NET 構成システムに指示します。ASP.NET は、リフレクションを使用してこの情報を取得し、要素のプロパティ オブジェクトを作成して必要な初期化を実行します。
カスタムの ConfigurationElementCollection を実装する方法を次のコード例に示します。関連するカスタム型の例については、ConfigurationSection および ConfigurationElement に関するトピックを参照してください。
Imports System Imports System.Configuration Imports System.Collections ' Define the UrlsCollection that contains ' UrlsConfigElement elements. Public Class UrlsCollection Inherits ConfigurationElementCollection Public Sub New() 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 MyBase.AddElementName = value End Set End Property Public Shadows Property ClearElementName() As String Get Return MyBase.ClearElementName End Get Set MyBase.AddElementName = 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 Overloads Public Sub Remove(ByVal name As String) BaseRemove(name) End Sub 'Remove Public Sub Clear() BaseClear() End Sub 'Clear ' Add custom code here. End Class 'UrlsCollection
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. } } }
<?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
派生クラス


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ConfigurationElementCollection メンバ
System.Configuration 名前空間
ElementInformation
ConfigurationElement クラス
ConfigurationElementCollectionType
ConfigurationProperty
ConfigurationPropertyCollection
ConfigurationSection
Weblioに収録されているすべての辞書からConfigurationElementCollection クラスを検索する場合は、下記のリンクをクリックしてください。

- ConfigurationElementCollection クラスのページへのリンク