NameValueConfigurationCollection Klasa

Definicja

Zawiera kolekcję NameValueConfigurationElement obiektów. Klasa ta nie może być dziedziczona.

public ref class NameValueConfigurationCollection sealed : System::Configuration::ConfigurationElementCollection
[System.Configuration.ConfigurationCollection(typeof(System.Configuration.NameValueConfigurationElement))]
public sealed class NameValueConfigurationCollection : System.Configuration.ConfigurationElementCollection
[<System.Configuration.ConfigurationCollection(typeof(System.Configuration.NameValueConfigurationElement))>]
type NameValueConfigurationCollection = class
    inherit ConfigurationElementCollection
Public NotInheritable Class NameValueConfigurationCollection
Inherits ConfigurationElementCollection
Dziedziczenie
Atrybuty

Przykłady

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

#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.
                // Make sure that you have a Web site on the
                // same server called TestConfig.
                string configPath = "/TestConfig";

                // 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)
                {
                    // Assign  domain name.
                    if (propertyItem.Name == "domain")
                        propertyItem.Value = "MyDomain";

                    if (propertyItem.Value != null)
                    {
                        // Enable SSL for cookie exchange.
                        if (propertyItem.Name == "cookieRequireSSL")
                            propertyItem.Value = true;

                        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);
                }

                // Assign the domain calue.
                configSection.Domain = myNameValConfigCollection["domain"].Value;
                // Assign the SSL required value.
                if (myNameValConfigCollection["cookieRequireSSL"].Value == "true")
                    configSection.CookieRequireSSL = true;

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

                // Save changes to the configuration file.
                // This modifies the Web.config of the TestConfig site.
                config.Save(ConfigurationSaveMode.Minimal, true);

                // Clear the collection.
                myNameValConfigCollection.Clear();
            }

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

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


Namespace Samples.AspNet
    Class UsingNameValueConfigurationCollection
        Public Shared Sub Main(ByVal args As String())
            Try
                ' Set the path of the config file. 
                ' Make sure that you have a Web site on the
                ' same server called TestConfig.
                Dim configPath As String = "/TestConfig"

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

                ' Get the section related object.
                Dim configSection _
                As System.Web.Configuration.AnonymousIdentificationSection = _
                DirectCast(config.GetSection("system.web/anonymousIdentification"),  _
                System.Web.Configuration.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 New NameValueConfigurationCollection()

                For Each propertyItem As PropertyInformation In configSection.ElementInformation.Properties
                    ' Assign  domain name.
                    If propertyItem.Name = "domain" Then
                        propertyItem.Value = "MyDomain"
                    End If

                    If propertyItem.Value <> Nothing Then
                        ' Enable SSL for cookie exchange.
                        If propertyItem.Name = "cookieRequireSSL" Then
                            propertyItem.Value = True
                        End If

                        Dim nameValConfigElement As New NameValueConfigurationElement(propertyItem.Name.ToString(), propertyItem.Value.ToString())

                        ' Add a NameValueConfigurationElement
                        ' to the collection.

                        myNameValConfigCollection.Add(nameValConfigElement)
                    End If
                Next

                ' 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.
                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

                ' Assign the domain calue.
                configSection.Domain = myNameValConfigCollection("domain").Value
                ' Assign the SSL required value.
                If myNameValConfigCollection("cookieRequireSSL").Value = "true" Then
                    configSection.CookieRequireSSL = True
                End If

                ' Remove domain from the collection.
                Dim myConfigElement As NameValueConfigurationElement = myNameValConfigCollection("domain")
                ' Remove method.
                myNameValConfigCollection.Remove(myConfigElement)

                ' Save changes to the configuration file.
                ' This modifies the Web.config of the TestConfig site.
                config.Save(ConfigurationSaveMode.Minimal, True)

                ' Clear the collection.
                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

Uwagi

Klasa NameValueConfigurationCollection umożliwia programowy dostęp do kolekcji NameValueConfigurationElement obiektów.

Konstruktory

NameValueConfigurationCollection()

Inicjuje nowe wystąpienie klasy NameValueConfigurationCollection.

Właściwości

AddElementName

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

(Odziedziczone po ConfigurationElementCollection)
AllKeys

Pobiera klucze do wszystkich elementów zawartych w obiekcie NameValueConfigurationCollection.

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 .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 reprezentującego hierarchię konfiguracji, do którego należy bieżące ConfigurationElement wystąpienie.

(Odziedziczone po ConfigurationElement)
ElementInformation

ElementInformation Pobiera obiekt, który zawiera informacje i funkcje ConfigurationElement obiektu, które nie można dostosowywać.

(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ą CurrentConfiguration , czy właściwość ma wartość 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]

Pobiera lub ustawia NameValueConfigurationElement 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.

(Odziedziczone po ConfigurationElement)
RemoveElementName

Pobiera lub ustawia nazwę ConfigurationElement obiektu do skojarzenia z operacją usuwania w ConfigurationElementCollection przypadku zastąpienia w 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 duplikatu ConfigurationElement do elementu ConfigurationElementCollection spowoduje zgłoszenie wyjątku.

(Odziedziczone po ConfigurationElementCollection)

Metody

Add(NameValueConfigurationElement)

NameValueConfigurationElement Dodaje obiekt do kolekcji.

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 elementów 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 obiekcie ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
BaseGetKey(Int32)

Pobiera klucz dla ConfigurationElement elementu w 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 obiekt ConfigurationElement w określonej lokalizacji indeksu.

(Odziedziczone po ConfigurationElementCollection)
Clear()

Czyści element NameValueConfigurationCollection.

CopyTo(ConfigurationElement[], Int32)

Kopiuje zawartość obiektu ConfigurationElementCollection do tablicy.

(Odziedziczone po ConfigurationElementCollection)
CreateNewElement()

Po zastąpieniu w klasie pochodnej program tworzy nowy ConfigurationElementelement .

(Odziedziczone po ConfigurationElementCollection)
CreateNewElement(String)

Tworzy nowy ConfigurationElement element po zastąpieniu 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.

(Odziedziczone po ConfigurationElementCollection)
GetEnumerator()

Pobiera element IEnumerator , który jest używany do iterowania przez element 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 wartość bieżącego wystąpienia.

(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 obiektu ConfigurationElementCollection.

(Odziedziczone po ConfigurationElementCollection)
IsModified()

Wskazuje, czy ConfigurationElementCollection ta operacja została zmodyfikowana od czasu ostatniego zapisania lub załadowania podczas zastępowania w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
IsReadOnly()

Wskazuje, czy ConfigurationElementCollection 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 można odnaleźć wymaganej właściwości.

(Odziedziczone po ConfigurationElement)
PostDeserialize()

Wywoływana po deserializacji.

(Odziedziczone po ConfigurationElement)
PreSerialize(XmlWriter)

Wywoływana przed serializacji.

(Odziedziczone po ConfigurationElement)
Remove(NameValueConfigurationElement)

NameValueConfigurationElement Usuwa obiekt z kolekcji na podstawie podanego parametru.

Remove(String)

NameValueConfigurationElement Usuwa obiekt z kolekcji na podstawie podanego parametru.

Reset(ConfigurationElement)

Resetuje element ConfigurationElementCollection do stanu niezmodyfikowanego, gdy zostanie zastąpiony w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
ResetModified()

Resetuje wartość IsModified() właściwości na false wartość po przesłonięciu w klasie pochodnej.

(Odziedziczone po ConfigurationElementCollection)
SerializeElement(XmlWriter, Boolean)

Zapisuje dane konfiguracji do elementu XML w pliku konfiguracji po zastąpieniu 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 obiektu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Zobacz też