KeyValueConfigurationCollection Klasa

Definicja

Zawiera kolekcję KeyValueConfigurationElement obiektów.

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
Dziedziczenie
Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak używać KeyValueConfigurationCollection typu.

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

Uwagi

Ta klasa reprezentuje kolekcję par, gdzie każda para składa się z ciągu obsługującego jako klucz kolekcji i wartość ciągu. Ponieważ pierwszy element jest kluczem, musi być unikatowy w całej kolekcji.

Konstruktory

KeyValueConfigurationCollection()

Inicjuje nowe wystąpienie klasy KeyValueConfigurationCollection.

Właściwości

AddElementName

Pobiera lub ustawia nazwę ConfigurationElement elementu do skojarzenia z operacją dodawania w przypadku zastąpienia w ConfigurationElementCollection klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
AllKeys

Pobiera klucze do wszystkich elementów zawartych w kolekcji KeyValueConfigurationCollection .

ClearElementName

Pobiera lub ustawia nazwę ConfigurationElement , która ma być skojarzona z operacją wyczyść w przypadku zastąpienia w ConfigurationElementCollection klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
CollectionType

Pobiera typ elementu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
Count

Pobiera liczbę elementów w kolekcji.

(Odziedziczone po ConfigurationElementCollection)
CurrentConfiguration

Pobiera odwołanie do wystąpienia najwyższego poziomu Configuration , które reprezentuje hierarchię konfiguracji, do którego należy bieżące ConfigurationElement wystąpienie.

(Odziedziczone po ConfigurationElement)
ElementInformation

ElementInformation Pobiera obiekt, który zawiera niezstosowalne informacje i funkcje ConfigurationElement obiektu.

(Odziedziczone po ConfigurationElement)
ElementName

Pobiera nazwę używaną do identyfikowania tej kolekcji elementów w pliku konfiguracji podczas zastępowania w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
ElementProperty

ConfigurationElementProperty Pobiera obiekt reprezentujący ConfigurationElement sam obiekt.

(Odziedziczone po ConfigurationElement)
EmitClear

Pobiera lub ustawia wartość określającą, czy kolekcja została wyczyszczone.

(Odziedziczone po ConfigurationElementCollection)
EvaluationContext

ContextInformation Pobiera obiekt dla ConfigurationElement obiektu.

(Odziedziczone po ConfigurationElement)
HasContext

Pobiera wartość wskazującą, czy CurrentConfiguration właściwość to null.

(Odziedziczone po ConfigurationElement)
IsSynchronized

Pobiera wartość wskazującą, czy dostęp do kolekcji jest synchronizowany.

(Odziedziczone po ConfigurationElementCollection)
Item[ConfigurationProperty]

Pobiera lub ustawia właściwość lub atrybut tego elementu konfiguracji.

(Odziedziczone po ConfigurationElement)
Item[String]

KeyValueConfigurationElement Pobiera obiekt na podstawie podanego parametru.

LockAllAttributesExcept

Pobiera kolekcję zablokowanych atrybutów.

(Odziedziczone po ConfigurationElement)
LockAllElementsExcept

Pobiera kolekcję zablokowanych elementów.

(Odziedziczone po ConfigurationElement)
LockAttributes

Pobiera kolekcję zablokowanych atrybutów.

(Odziedziczone po ConfigurationElement)
LockElements

Pobiera kolekcję zablokowanych elementów.

(Odziedziczone po ConfigurationElement)
LockItem

Pobiera lub ustawia wartość wskazującą, czy element jest zablokowany.

(Odziedziczone po ConfigurationElement)
Properties

Pobiera kolekcję właściwości konfiguracji.

RemoveElementName

Pobiera lub ustawia nazwę ConfigurationElement , która ma być skojarzona z operacją usuwania w przypadku zastąpienia w ConfigurationElementCollection klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
SyncRoot

Pobiera obiekt używany do synchronizowania dostępu do obiektu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
ThrowOnDuplicate

Pobiera wartość wskazującą, czy próba dodania zduplikowanego KeyValueConfigurationElement obiektu do KeyValueConfigurationCollection kolekcji spowoduje zgłoszenie wyjątku.

Metody

Add(KeyValueConfigurationElement)

KeyValueConfigurationElement Dodaje obiekt do kolekcji na podstawie podanych parametrów.

Add(String, String)

KeyValueConfigurationElement Dodaje obiekt do kolekcji na podstawie podanych parametrów.

BaseAdd(ConfigurationElement)

Dodaje element konfiguracji do elementu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
BaseAdd(ConfigurationElement, Boolean)

Dodaje element konfiguracji do kolekcji elementów konfiguracji.

(Odziedziczone po ConfigurationElementCollection)
BaseAdd(Int32, ConfigurationElement)

Dodaje element konfiguracji do kolekcji elementów konfiguracji.

(Odziedziczone po ConfigurationElementCollection)
BaseClear()

Usuwa wszystkie obiekty elementu konfiguracji z kolekcji.

(Odziedziczone po ConfigurationElementCollection)
BaseGet(Int32)

Pobiera element konfiguracji w określonej lokalizacji indeksu.

(Odziedziczone po ConfigurationElementCollection)
BaseGet(Object)

Zwraca element konfiguracji z określonym kluczem.

(Odziedziczone po ConfigurationElementCollection)
BaseGetAllKeys()

Zwraca tablicę kluczy dla wszystkich elementów konfiguracji zawartych w elemecie ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
BaseGetKey(Int32)

Pobiera klucz dla ConfigurationElement określonej lokalizacji indeksu.

(Odziedziczone po ConfigurationElementCollection)
BaseIndexOf(ConfigurationElement)

Wskazuje indeks określonego ConfigurationElementelementu .

(Odziedziczone po ConfigurationElementCollection)
BaseIsRemoved(Object)

Wskazuje, czy ConfigurationElement element z określonym kluczem został usunięty z elementu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
BaseRemove(Object)

Usuwa obiekt ConfigurationElement z kolekcji.

(Odziedziczone po ConfigurationElementCollection)
BaseRemoveAt(Int32)

Usuwa element ConfigurationElement w określonej lokalizacji indeksu.

(Odziedziczone po ConfigurationElementCollection)
Clear()

Czyści KeyValueConfigurationCollection kolekcję.

CopyTo(ConfigurationElement[], Int32)

Kopiuje zawartość obiektu ConfigurationElementCollection do tablicy.

(Odziedziczone po ConfigurationElementCollection)
CreateNewElement()

Po zastąpieniu w klasie CreateNewElement() pochodnej metoda tworzy nowy KeyValueConfigurationElement obiekt.

CreateNewElement(String)

Tworzy nowy ConfigurationElement element po przesłonięciu w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
DeserializeElement(XmlReader, Boolean)

Odczytuje kod XML z pliku konfiguracji.

(Odziedziczone po ConfigurationElement)
Equals(Object)

Porównuje obiekt ConfigurationElementCollection z określonym obiektem.

(Odziedziczone po ConfigurationElementCollection)
GetElementKey(ConfigurationElement)

Pobiera klucz elementu dla określonego elementu konfiguracji podczas zastępowania w klasie pochodnej.

GetEnumerator()

Pobiera element IEnumerator służący do iterowania za pośrednictwem elementu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
GetHashCode()

Pobiera unikatową wartość reprezentującą ConfigurationElementCollection wystąpienie.

(Odziedziczone po ConfigurationElementCollection)
GetTransformedAssemblyString(String)

Zwraca przekształconą wersję określonej nazwy zestawu.

(Odziedziczone po ConfigurationElement)
GetTransformedTypeString(String)

Zwraca przekształconą wersję określonej nazwy typu.

(Odziedziczone po ConfigurationElement)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
Init()

ConfigurationElement Ustawia obiekt na stan początkowy.

(Odziedziczone po ConfigurationElement)
InitializeDefault()

Służy do inicjowania domyślnego zestawu wartości dla ConfigurationElement obiektu.

(Odziedziczone po ConfigurationElement)
IsElementName(String)

Wskazuje, czy określony ConfigurationElement element istnieje w obiekcie ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
IsElementRemovable(ConfigurationElement)

Wskazuje, czy określony ConfigurationElement element można usunąć z elementu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
IsModified()

Wskazuje, czy została ConfigurationElementCollection ona zmodyfikowana od czasu ostatniego zapisania lub załadowania podczas przesłonięcia w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
IsReadOnly()

Wskazuje, ConfigurationElementCollection czy obiekt jest tylko do odczytu.

(Odziedziczone po ConfigurationElementCollection)
ListErrors(IList)

Dodaje błędy nieprawidłowej właściwości w tym ConfigurationElement obiekcie i we wszystkich podelementach do przekazanej listy.

(Odziedziczone po ConfigurationElement)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
OnDeserializeUnrecognizedAttribute(String, String)

Pobiera wartość wskazującą, czy podczas deserializacji napotkano nieznany atrybut.

(Odziedziczone po ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Powoduje, że system konfiguracji zgłasza wyjątek.

(Odziedziczone po ConfigurationElementCollection)
OnRequiredPropertyNotFound(String)

Zgłasza wyjątek, gdy nie znaleziono wymaganej właściwości.

(Odziedziczone po ConfigurationElement)
PostDeserialize()

Wywoływana po deserializacji.

(Odziedziczone po ConfigurationElement)
PreSerialize(XmlWriter)

Wywoływane przed serializacji.

(Odziedziczone po ConfigurationElement)
Remove(String)

KeyValueConfigurationElement Usuwa obiekt z kolekcji.

Reset(ConfigurationElement)

Resetuje element ConfigurationElementCollection do stanu niezmodyfikowanego po przesłonięciu w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
ResetModified()

Resetuje wartość IsModified() właściwości do false wartości podczas zastępowania w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
SerializeElement(XmlWriter, Boolean)

Zapisuje dane konfiguracji do elementu XML w pliku konfiguracji podczas zastępowania w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
SerializeToXmlElement(XmlWriter, String)

Zapisuje zewnętrzne tagi tego elementu konfiguracji do pliku konfiguracji po zaimplementowaniu w klasie pochodnej.

(Odziedziczone po ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

Ustawia właściwość na określoną wartość.

(Odziedziczone po ConfigurationElement)
SetReadOnly()

IsReadOnly() Ustawia właściwość obiektu ConfigurationElementCollection i dla wszystkich elementów podrzędnych.

(Odziedziczone po ConfigurationElementCollection)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

Odwraca efekt scalania informacji o konfiguracji z różnych poziomów hierarchii konfiguracji.

(Odziedziczone po ConfigurationElementCollection)

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje element ConfigurationElementCollection do tablicy.

(Odziedziczone po ConfigurationElementCollection)

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy elementu IEnumerable do określonego typu.

OfType<TResult>(IEnumerable)

Filtruje elementy elementu IEnumerable na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy