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

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

NameValueConfigurationCollection クラス

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

NameValueConfigurationElement オブジェクトコレクション格納します。このクラス継承できません。

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

Public NotInheritable Class
 NameValueConfigurationCollection
    Inherits ConfigurationElementCollection
Dim instance As NameValueConfigurationCollection
public sealed class NameValueConfigurationCollection
 : ConfigurationElementCollection
public ref class NameValueConfigurationCollection
 sealed : public ConfigurationElementCollection
public final class NameValueConfigurationCollection
 extends ConfigurationElementCollection
public final class NameValueConfigurationCollection
 extends ConfigurationElementCollection
解説解説

NameValueConfigurationCollection クラス使用すると、NameValueConfigurationElement オブジェクトコレクションプログラムかアクセスできます

使用例使用例

NameValueConfigurationCollection 型を使用する方法次のコード例示します

Imports System
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Collections
Imports System.Text

Namespace Samples.AspNet
  Class UsingNameValueConfigurationCollection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String
 = ""

        ' Get the Web application configuration object.
        Dim config As System.Configuration.Configuration
 = _
         WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the section related object.
        Dim configSection As _
        AnonymousIdentificationSection = _
         CType(config.GetSection("system.web/anonymousIdentification"),
 _
         AnonymousIdentificationSection)

        ' Display title and info.
        Console.WriteLine("Configuration Info")
        Console.WriteLine()

        ' Display Config details.
        Console.WriteLine("File Path: {0}", _
          config.FilePath)
        Console.WriteLine("Section Path: {0}", _
          configSection.SectionInformation.Name)
        Console.WriteLine()

        ' Create a NameValueConfigurationCollection object.
        Dim myNameValConfigCollection As NameValueConfigurationCollection
 = _
        New NameValueConfigurationCollection()

        For Each propertyItem As
 PropertyInformation In _
         configSection.ElementInformation.Properties
          Dim nameValConfigElement As NameValueConfigurationElement
 = _
           New NameValueConfigurationElement _
           (propertyItem.Name.ToString(), propertyItem.Value.ToString())
          ' Add a NameValueConfigurationElement
          ' to the collection.
          myNameValConfigCollection.Add(nameValConfigElement)
        Next

        ' Count property.
        Console.WriteLine("Collection Count: {0}",
 _
         myNameValConfigCollection.Count)

        ' Item property.
        Console.WriteLine("Value of property
 'enabled': {0}", _
         myNameValConfigCollection.Item("enabled").Value)

        ' Display the contents of the collection.
        For Each configItem As
 NameValueConfigurationElement In _
         myNameValConfigCollection
          Console.WriteLine()
          Console.WriteLine("Configuration Details:")
          Console.WriteLine("Name: {0}", configItem.Name)
          Console.WriteLine("Value: {0}", configItem.Value)
        Next

        ' Remove method.
        Dim myConfigElement As NameValueConfigurationElement
 = _
         myNameValConfigCollection.Item("domain")
        myNameValConfigCollection.Remove(myConfigElement)

        ' Clear method.
        myNameValConfigCollection.Clear()

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait.
      Console.ReadLine()
    End Sub
  End Class
End Namespace
#region Using directives

using System;
using System.Configuration;
using System.Web.Configuration;
using System.Collections;
using System.Text;

#endregion

namespace Samples.AspNet
{
  class UsingNameValueConfigurationCollection
  {
    static void Main(string[]
 args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config =
          WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        AnonymousIdentificationSection configSection =
          (AnonymousIdentificationSection)config.GetSection
          ("system.web/anonymousIdentification");

        // Display title and info.
        Console.WriteLine("Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);
        Console.WriteLine();

        // Create a NameValueConfigurationCollection object.
        NameValueConfigurationCollection myNameValConfigCollection =
          new NameValueConfigurationCollection();

        foreach (PropertyInformation propertyItem in
          configSection.ElementInformation.Properties)
        {
          NameValueConfigurationElement nameValConfigElement =
            new NameValueConfigurationElement
            (propertyItem.Name.ToString(), propertyItem.Value.ToString());
          // Add a NameValueConfigurationElement
          // to the collection.
          myNameValConfigCollection.Add(nameValConfigElement);
        }

        // Count property.
        Console.WriteLine("Collection Count: {0}",
         myNameValConfigCollection.Count);

        // Item property.
        Console.WriteLine("Value of property 'enabled': {0}",
         myNameValConfigCollection["enabled"].Value);

        // Display the contents of the collection.
        foreach (NameValueConfigurationElement configItem
          in myNameValConfigCollection)
        {
          Console.WriteLine();
          Console.WriteLine("Configuration Details:");
          Console.WriteLine("Name: {0}", configItem.Name);
          Console.WriteLine("Value: {0}", configItem.Value);
        }

        // Remove method.
        NameValueConfigurationElement myConfigElement =
          myNameValConfigCollection["domain"];
        myNameValConfigCollection.Remove(myConfigElement);

        // Clear method.
        myNameValConfigCollection.Clear();
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait.
      Console.ReadLine();
    }
  }
}
継承階層継承階層
System.Object
   System.Configuration.ConfigurationElement
     System.Configuration.ConfigurationElementCollection
      System.Configuration.NameValueConfigurationCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
NameValueConfigurationCollection メンバ
System.Configuration 名前空間
NameValueConfigurationElement


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

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

辞書ショートカット

すべての辞書の索引

「NameValueConfigurationCollection クラス」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS