KeyValueConfigurationCollection Třída

Definice

Obsahuje kolekci KeyValueConfigurationElement objektů.

public ref class KeyValueConfigurationCollection : System::Configuration::ConfigurationElementCollection
[System.Configuration.ConfigurationCollection(typeof(System.Configuration.KeyValueConfigurationElement))]
public class KeyValueConfigurationCollection : System.Configuration.ConfigurationElementCollection
[<System.Configuration.ConfigurationCollection(typeof(System.Configuration.KeyValueConfigurationElement))>]
type KeyValueConfigurationCollection = class
    inherit ConfigurationElementCollection
Public Class KeyValueConfigurationCollection
Inherits ConfigurationElementCollection
Dědičnost
Atributy

Příklady

Následující příklad kódu ukazuje, jak použít KeyValueConfigurationCollection typ.

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

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

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

        // Get the section related object.
        AppSettingsSection configSection =
          (AppSettingsSection)config.GetSection
          ("appSettings");

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

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

        // Create the KeyValueConfigurationElement.
        KeyValueConfigurationElement myAdminKeyVal = 
          new KeyValueConfigurationElement(
          "myAdminTool", "admin.aspx");

        // Determine if the configuration contains
        // any KeyValueConfigurationElements.
        KeyValueConfigurationCollection configSettings = 
          config.AppSettings.Settings;
        if (configSettings.AllKeys.Length == 0)
        {
          // Add KeyValueConfigurationElement to collection.
          config.AppSettings.Settings.Add(myAdminKeyVal);

          if (!configSection.SectionInformation.IsLocked)
          {
            config.Save();
            Console.WriteLine("** Configuration updated.");
          }
          else
          {
            Console.WriteLine("** Could not update, section is locked.");
          }
        }

        // Get the KeyValueConfigurationCollection 
        // from the configuration.
        KeyValueConfigurationCollection settings = 
          config.AppSettings.Settings;

        // Display each KeyValueConfigurationElement.
        foreach (KeyValueConfigurationElement keyValueElement in settings)
        {
          Console.WriteLine("Key: {0}", keyValueElement.Key);
          Console.WriteLine("Value: {0}", keyValueElement.Value);
          Console.WriteLine();
        }
      }
      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration

Namespace Samples.Aspnet.Config
  Class KeyValueConfigCollection
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = "/aspnet"

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

        ' Get the section related object.
        Dim configSection As System.Configuration.AppSettingsSection = _
        CType(config.GetSection("appSettings"), System.Configuration.AppSettingsSection)

        '      Dim configSection As AppSettingsSection = _
        '       (AppSettingsSection)config.GetSection("appSettings")

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

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

        ' Create the KeyValueConfigurationElement.
        Dim myAdminKeyVal As KeyValueConfigurationElement = _
          New KeyValueConfigurationElement _
          ("myAdminTool", "admin.aspx")


        ' Determine if the configuration contains
        ' any KeyValueConfigurationElements.
        Dim configSettings As KeyValueConfigurationCollection = _
        config.AppSettings.Settings()

        If configSettings.AllKeys.Length = 0 Then
          ' Add KeyValueConfigurationElement to collection.
          config.AppSettings.Settings.Add(myAdminKeyVal)

          If Not configSection.SectionInformation.IsLocked Then
            config.Save()
            Console.WriteLine("** Configuration updated.")
          Else
            Console.WriteLine("** Could not update, section is locked.")
          End If
        End If

        ' Get the KeyValueConfigurationCollection 
        ' from the configuration.
        Dim settings As KeyValueConfigurationCollection = _
        config.AppSettings.Settings()

        ' Display each KeyValueConfigurationElement.
        Dim keyValueElement As KeyValueConfigurationElement
        For Each keyValueElement In settings
          Console.WriteLine("Key: {0}", keyValueElement.Key)
          Console.WriteLine("Value: {0}", keyValueElement.Value)
          Console.WriteLine()
        Next

      Catch e As System.ArgumentException
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try
      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

Poznámky

Tato třída představuje kolekci párů, kde každý pár se skládá z řetězce, který slouží jako klíč kolekce a řetězcové hodnoty. Vzhledem k tomu, že první prvek je klíč, musí být v rámci kolekce jedinečný.

Konstruktory

KeyValueConfigurationCollection()

Inicializuje novou instanci KeyValueConfigurationCollection třídy .

Vlastnosti

AddElementName

Získá nebo nastaví název objektu, který ConfigurationElement se má přidružit k operaci přidání v ConfigurationElementCollection při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
AllKeys

Získá klíče ke všem položkám obsaženým v kolekci KeyValueConfigurationCollection .

ClearElementName

Získá nebo nastaví název pro ConfigurationElement přidružení k operaci clear v při ConfigurationElementCollection přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
CollectionType

Získá typ objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
Count

Získá počet elementů v kolekci.

(Zděděno od ConfigurationElementCollection)
CurrentConfiguration

Získá odkaz na instanci nejvyšší úrovně Configuration , která představuje hierarchii konfigurace, do které aktuální ConfigurationElement instance patří.

(Zděděno od ConfigurationElement)
ElementInformation

ElementInformation Získá objekt, který obsahuje neuzpůsobitelné informace a funkce objektuConfigurationElement.

(Zděděno od ConfigurationElement)
ElementName

Získá název použitý k identifikaci této kolekce elementů v konfiguračním souboru při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
ElementProperty

ConfigurationElementProperty Získá objekt, který představuje ConfigurationElement objekt samotný.

(Zděděno od ConfigurationElement)
EmitClear

Získá nebo nastaví hodnotu, která určuje, zda byla kolekce vymazána.

(Zděděno od ConfigurationElementCollection)
EvaluationContext

ContextInformation Získá objekt pro ConfigurationElement objekt .

(Zděděno od ConfigurationElement)
HasContext

Získá hodnotu, která označuje, zda CurrentConfiguration je nullvlastnost .

(Zděděno od ConfigurationElement)
IsSynchronized

Získá hodnotu označující, zda přístup ke kolekci je synchronizován.

(Zděděno od ConfigurationElementCollection)
Item[ConfigurationProperty]

Získá nebo nastaví vlastnost nebo atribut tohoto elementu konfigurace.

(Zděděno od ConfigurationElement)
Item[String]

KeyValueConfigurationElement Získá objekt na základě zadaného parametru.

LockAllAttributesExcept

Získá kolekci uzamčených atributů.

(Zděděno od ConfigurationElement)
LockAllElementsExcept

Získá kolekci uzamčených prvků.

(Zděděno od ConfigurationElement)
LockAttributes

Získá kolekci uzamčených atributů.

(Zděděno od ConfigurationElement)
LockElements

Získá kolekci uzamčených prvků.

(Zděděno od ConfigurationElement)
LockItem

Získá nebo nastaví hodnotu označující, zda je prvek uzamčen.

(Zděděno od ConfigurationElement)
Properties

Získá kolekci vlastností konfigurace.

RemoveElementName

Získá nebo nastaví název objektu, který se má přidružit ConfigurationElement k operaci odebrání v při ConfigurationElementCollection přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
SyncRoot

Získá objekt použitý k synchronizaci přístupu k .ConfigurationElementCollection

(Zděděno od ConfigurationElementCollection)
ThrowOnDuplicate

Získá hodnotu označující, zda pokus o přidání duplicitní KeyValueConfigurationElement objektu KeyValueConfigurationCollection do kolekce způsobí výjimku být vyvolán.

Metody

Add(KeyValueConfigurationElement)

KeyValueConfigurationElement Přidá objekt do kolekce na základě zadaných parametrů.

Add(String, String)

KeyValueConfigurationElement Přidá objekt do kolekce na základě zadaných parametrů.

BaseAdd(ConfigurationElement)

Přidá element konfigurace do objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
BaseAdd(ConfigurationElement, Boolean)

Přidá element konfigurace do kolekce elementů konfigurace.

(Zděděno od ConfigurationElementCollection)
BaseAdd(Int32, ConfigurationElement)

Přidá element konfigurace do kolekce elementů konfigurace.

(Zděděno od ConfigurationElementCollection)
BaseClear()

Odebere z kolekce všechny objekty elementů konfigurace.

(Zděděno od ConfigurationElementCollection)
BaseGet(Int32)

Získá konfigurační prvek v zadaném umístění indexu.

(Zděděno od ConfigurationElementCollection)
BaseGet(Object)

Vrátí element konfigurace se zadaným klíčem.

(Zděděno od ConfigurationElementCollection)
BaseGetAllKeys()

Vrátí pole klíčů pro všechny konfigurační prvky obsažené v objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
BaseGetKey(Int32)

Získá klíč pro v ConfigurationElement zadaném umístění indexu.

(Zděděno od ConfigurationElementCollection)
BaseIndexOf(ConfigurationElement)

Označuje index zadaného ConfigurationElementobjektu .

(Zděděno od ConfigurationElementCollection)
BaseIsRemoved(Object)

Určuje, jestli ConfigurationElement byl se zadaným klíčem odebrán z objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
BaseRemove(Object)

Odebere z kolekce objekt ConfigurationElement .

(Zděděno od ConfigurationElementCollection)
BaseRemoveAt(Int32)

Odebere objekt v ConfigurationElement zadaném umístění indexu.

(Zděděno od ConfigurationElementCollection)
Clear()

Vymaže kolekci KeyValueConfigurationCollection .

CopyTo(ConfigurationElement[], Int32)

Zkopíruje obsah objektu ConfigurationElementCollection do pole.

(Zděděno od ConfigurationElementCollection)
CreateNewElement()

Při přepsání v odvozené třídě CreateNewElement() metoda vytvoří nový KeyValueConfigurationElement objekt.

CreateNewElement(String)

Vytvoří nový ConfigurationElement při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
DeserializeElement(XmlReader, Boolean)

Načte XML z konfiguračního souboru.

(Zděděno od ConfigurationElement)
Equals(Object)

Porovná objekt se ConfigurationElementCollection zadaným objektem.

(Zděděno od ConfigurationElementCollection)
GetElementKey(ConfigurationElement)

Získá klíč prvku pro zadaný konfigurační prvek při přepsání v odvozené třídě.

GetEnumerator()

Získá , IEnumerator který se používá k iteraci přes ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
GetHashCode()

Získá jedinečnou hodnotu představující ConfigurationElementCollection instanci.

(Zděděno od ConfigurationElementCollection)
GetTransformedAssemblyString(String)

Vrátí transformovanou verzi zadaného názvu sestavení.

(Zděděno od ConfigurationElement)
GetTransformedTypeString(String)

Vrátí transformovanou verzi zadaného názvu typu.

(Zděděno od ConfigurationElement)
GetType()

Type Získá z aktuální instance.

(Zděděno od Object)
Init()

ConfigurationElement Nastaví objekt do počátečního stavu.

(Zděděno od ConfigurationElement)
InitializeDefault()

Slouží k inicializaci výchozí sady hodnot objektu ConfigurationElement .

(Zděděno od ConfigurationElement)
IsElementName(String)

Určuje, zda zadaná ConfigurationElement hodnota existuje v objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
IsElementRemovable(ConfigurationElement)

Určuje, zda lze zadanou ConfigurationElement položku odebrat z objektu ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
IsModified()

Určuje, zda ConfigurationElementCollection byl změněn od posledního uložení nebo načtení při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
IsReadOnly()

Určuje, jestli ConfigurationElementCollection je objekt jen pro čtení.

(Zděděno od ConfigurationElementCollection)
ListErrors(IList)

Přidá chyby neplatné vlastnosti v tomto ConfigurationElement objektu a ve všech podelementech, do předaného seznamu.

(Zděděno od ConfigurationElement)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
OnDeserializeUnrecognizedAttribute(String, String)

Získá hodnotu označující, zda je zjištěn neznámý atribut během deserializace.

(Zděděno od ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Způsobí, že konfigurační systém vyvolá výjimku.

(Zděděno od ConfigurationElementCollection)
OnRequiredPropertyNotFound(String)

Vyvolá výjimku, pokud není nalezena požadovaná vlastnost.

(Zděděno od ConfigurationElement)
PostDeserialize()

Volána po deserializaci.

(Zděděno od ConfigurationElement)
PreSerialize(XmlWriter)

Volána před serializací.

(Zděděno od ConfigurationElement)
Remove(String)

Odebere KeyValueConfigurationElement objekt z kolekce.

Reset(ConfigurationElement)

ConfigurationElementCollection Obnoví do stavu beze změny při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
ResetModified()

Obnoví hodnotu IsModified() vlastnosti na false při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
SerializeElement(XmlWriter, Boolean)

Zapíše konfigurační data do elementu XML v konfiguračním souboru při přepsání v odvozené třídě.

(Zděděno od ConfigurationElementCollection)
SerializeToXmlElement(XmlWriter, String)

Zapíše vnější značky tohoto konfiguračního prvku do konfiguračního souboru při implementaci v odvozené třídě.

(Zděděno od ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

Nastaví vlastnost na zadanou hodnotu.

(Zděděno od ConfigurationElement)
SetReadOnly()

IsReadOnly() Nastaví vlastnost pro ConfigurationElementCollection objekt a pro všechny dílčí prvky.

(Zděděno od ConfigurationElementCollection)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

Obrátí účinek sloučení informací o konfiguraci z různých úrovní hierarchie konfigurace.

(Zděděno od ConfigurationElementCollection)

Explicitní implementace rozhraní

ICollection.CopyTo(Array, Int32)

Zkopíruje objekt do ConfigurationElementCollection pole.

(Zděděno od ConfigurationElementCollection)

Metody rozšíření

Cast<TResult>(IEnumerable)

Přetypuje prvky objektu na IEnumerable zadaný typ.

OfType<TResult>(IEnumerable)

Filtruje prvky objektu IEnumerable na základě zadaného typu.

AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede objekt na IEnumerableIQueryable.

Platí pro