NameValueConfigurationCollection Třída

Definice

Obsahuje kolekci NameValueConfigurationElement objektů. Tato třída se nemůže dědit.

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
Dědičnost
Atributy

Příklady

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

#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

Poznámky

Třída NameValueConfigurationCollection umožňuje programově přistupovat k kolekci NameValueConfigurationElement objektů.

Konstruktory

Name Description
NameValueConfigurationCollection()

Inicializuje novou instanci NameValueConfigurationCollection třídy.

Vlastnosti

Name Description
AddElementName

Získá nebo nastaví název ConfigurationElement 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 souboru NameValueConfigurationCollection.

ClearElementName

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

(Zděděno od ConfigurationElementCollection)
CollectionType

Získá typ ConfigurationElementCollection.

(Zděděno od ConfigurationElementCollection)
Count

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

(Zděděno od ConfigurationElementCollection)
CurrentConfiguration

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

(Zděděno od ConfigurationElement)
ElementInformation

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

(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

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

(Zděděno od ConfigurationElement)
EmitClear

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

(Zděděno od ConfigurationElementCollection)
EvaluationContext

Získá objekt ContextInformation pro objekt ConfigurationElement.

(Zděděno od ConfigurationElement)
HasContext

Získá hodnotu, která určuje, zda CurrentConfiguration vlastnost je null.

(Zděděno od ConfigurationElement)
IsSynchronized

Získá hodnotu určující, zda je přístup ke kolekci 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]

Získá nebo nastaví NameValueConfigurationElement 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í.

(Zděděno od ConfigurationElement)
RemoveElementName

Získá nebo nastaví název ConfigurationElement přidružit k operaci remove v ConfigurationElementCollection při 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 přidat duplicitní ConfigurationElement do ConfigurationElementCollection způsobí vyvolání výjimky.

(Zděděno od ConfigurationElementCollection)

Metody

Name Description
Add(NameValueConfigurationElement)

NameValueConfigurationElement Přidá objekt do kolekce.

BaseAdd(ConfigurationElement, Boolean)

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

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

Přidá element konfigurace do ConfigurationElementCollection.

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

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

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

Odebere všechny objekty elementu konfigurace z kolekce.

(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í prvek konfigurace se zadaným klíčem.

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

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

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

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

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

Označuje index zadaného ConfigurationElement.

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

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

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

Odebere ConfigurationElement z kolekce.

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

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

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

Vymaže .NameValueConfigurationCollection

CopyTo(ConfigurationElement[], Int32)

Zkopíruje obsah ConfigurationElementCollection do pole.

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

Při přepsání v odvozené třídě vytvoří novou ConfigurationElement.

(Zděděno od ConfigurationElementCollection)
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á ConfigurationElementCollection se zadaným objektem.

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

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

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

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

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

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

(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()

Získá Type aktuální instance.

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

Nastaví objekt ConfigurationElement na jeho počáteční stav.

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

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

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

Určuje, zda zadaný ConfigurationElement existuje v ConfigurationElementCollection.

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

Určuje, zda zadané ConfigurationElement lze odebrat z ConfigurationElementCollection.

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

Označuje, zda byl tento ConfigurationElementCollection 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, zda je objekt ConfigurationElementCollection jen pro čtení.

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

Přidá chyby neplatné vlastnosti v tomto ConfigurationElement objektu a ve všech dílčích poplatcích do předaného seznamu.

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

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

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

Získá hodnotu určující, zda neznámý atribut je zjištěn 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 nebyla nalezena požadovaná vlastnost.

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

Volal po deserializaci.

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

Volá se před serializací.

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

Odebere NameValueConfigurationElement objekt z kolekce na základě zadaného parametru.

Remove(String)

Odebere NameValueConfigurationElement objekt z kolekce na základě zadaného parametru.

Reset(ConfigurationElement)

Obnoví ConfigurationElementCollection do jeho nemodifikovaného stavu při přepsání v odvozené třídě.

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

Obnoví hodnotu vlastnosti IsModified() 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()

Nastaví vlastnost IsReadOnly() objektu ConfigurationElementCollection 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í

Name Description
ICollection.CopyTo(Array, Int32)

Zkopíruje ConfigurationElementCollection do pole.

(Zděděno od ConfigurationElementCollection)

Metody rozšíření

Name Description
AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede IEnumerable na IQueryable.

Cast<TResult>(IEnumerable)

Přetypuje prvky IEnumerable na zadaný typ.

OfType<TResult>(IEnumerable)

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

Platí pro

Viz také