ConfigurationElementCollection クラスとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ConfigurationElementCollection クラスの意味・解説 

ConfigurationElementCollection クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

子要素コレクション格納する構成要素表します

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

Public MustInherit Class
 ConfigurationElementCollection
    Inherits ConfigurationElement
    Implements ICollection, IEnumerable
Dim instance As ConfigurationElementCollection
public abstract class ConfigurationElementCollection
 : ConfigurationElement, ICollection, IEnumerable
public ref class ConfigurationElementCollection
 abstract : public ConfigurationElement, ICollection, IEnumerable
public abstract class ConfigurationElementCollection
 extends ConfigurationElement implements ICollection, IEnumerable
public abstract class ConfigurationElementCollection
 extends ConfigurationElement implements 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.Object
   System.Configuration.ConfigurationElement
    System.Configuration.ConfigurationElementCollection
       派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConfigurationElementCollection メンバ
System.Configuration 名前空間
ElementInformation
ConfigurationElement クラス
ConfigurationElementCollectionType
ConfigurationProperty
ConfigurationPropertyCollection
ConfigurationSection


このページでは「.NET Framework クラス ライブラリ リファレンス」からConfigurationElementCollection クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConfigurationElementCollection クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConfigurationElementCollection クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ConfigurationElementCollection クラス」の関連用語

ConfigurationElementCollection クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ConfigurationElementCollection クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS