ConfigurationElement Klasse

Definition

Stellt ein Element in einer Konfigurationsdatei dar.

public ref class ConfigurationElement
public class ConfigurationElement
type ConfigurationElement = class
Public Class ConfigurationElement
Vererbung
ConfigurationElement
Abgeleitet

Beispiele

Im folgenden Beispiel werden mehrere Methoden und Eigenschaften der ConfigurationElement -Klasse implementiert. In diesem Beispiel wird ein ConfigurationSection -Objekt für den moduleProvider Abschnitt abgerufen und ein ConfigurationElementCollection aus diesem Abschnitt abgerufen. In diesem Beispiel wird jede ConfigurationElement der abgerufenen Auflistungen durchlaufen.

[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetElementCollection()
{
    // Use an ArrayList to transfer objects to the client.
    ArrayList arrayOfConfigPropertyBags = new ArrayList();

    ServerManager serverManager = new ServerManager();
    Configuration administrationConfig = serverManager.GetAdministrationConfiguration();
    ConfigurationSection moduleProvidersSection = 
        administrationConfig.GetSection("moduleProviders");
    ConfigurationElementCollection elementCollection = 
        moduleProvidersSection.GetCollection();
    // If there is a configuration element with the name of TestDemo(Modified), delete it.
    ConfigurationElement elementtoremove = null;
    foreach (ConfigurationElement moduleproviderelement in elementCollection)
    {
        if(moduleproviderelement.Attributes["name"].Value.ToString() == "TestDemo(Modified)")
        {
            elementtoremove = moduleproviderelement;
        }
    }
    if (elementtoremove != null)
    {
        elementCollection.Remove(elementtoremove);
    }
    foreach (ConfigurationElement moduleproviderelement in elementCollection)
    {
        PropertyBag elementBag = new PropertyBag();
        elementBag[ConfigurationDemoGlobals.SchemaName] = 
            moduleproviderelement.Schema.Name;
        elementBag[ConfigurationDemoGlobals.ElementTagName] = 
            moduleproviderelement.ElementTagName;
        ArrayList attributeArrayList = new ArrayList();
        // Loop through all attributes in the element attribute list.
        // Get the attribute name and value.
        foreach (ConfigurationAttribute attribute in moduleproviderelement.Attributes)
        {
            PropertyBag attributeBag = new PropertyBag();
            attributeBag[ConfigurationDemoGlobals.AttributeName] = attribute.Name;
            attributeBag[ConfigurationDemoGlobals.AttributeValue] = attribute.Value;
            // Change the value of the provider name "TestDemo" to "TestDemo(Modified)".
            if (attribute.Value.ToString() == "TestDemo")
            {
                // Use any of the following lines to set the attribute value.
                // attribute.Value = "TestDemo(Modified)";
                moduleproviderelement.SetAttributeValue(
                    "name", "TestDemo(Modified)");
                // moduleproviderelement["name"] = "TestDemo(Modified)";
                // Use any of the following lines to retrieve the attribute value.
                // attributeBag[ConfigurationDemoGlobals.AttributeName] = "name";
                attributeBag[ConfigurationDemoGlobals.AttributeName] =
                    moduleproviderelement.GetAttributeValue("name");
                // attributeBag[ConfigurationDemoGlobals.AttributeName] =
                //    moduleproviderelement["name"];
                // Set the element's lockItem attribute.
                moduleproviderelement.SetMetadata("lockItem", true); // persisted in Administration.config          

            }
            attributeArrayList.Add(attributeBag);
        }
        elementBag[ConfigurationDemoGlobals.AttributeArrayList] = attributeArrayList;
        arrayOfConfigPropertyBags.Add(elementBag);
    }
    // Create a new element. It must have a unique name.
    ConfigurationElement newelement;
    bool newelementexists = false;
    foreach (ConfigurationElement element in elementCollection)
    {
        if (element.Attributes["name"].Value.ToString() == "TestDemo")
        {
            newelementexists = true;
        }
    }
    if (!newelementexists)
    {
        newelement = elementCollection.CreateElement("add");
        newelement.Attributes["name"].Value = "TestDemo";
        newelement.Attributes["Type"].Value = "TestDemo.TestDemoModuleProvider, TestDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=104f78e73dc54601";
        elementCollection.Add(newelement);
    }
    // CommitChanges to persist the changes to Administration.config.
    serverManager.CommitChanges();
    return arrayOfConfigPropertyBags;
}

Hinweise

Dies ist die Basisklasse für viele Konfigurationsentitäten, einschließlich Konfigurationsabschnitten, Sammlungseinträgen und geschachtelten Elementen in einem Abschnitt.

Konstruktoren

ConfigurationElement()

Initialisiert eine neue Instanz der ConfigurationElement-Klasse.

Eigenschaften

Attributes

Ruft eine Konfigurationsattributeauflistung ab, die die Liste der Attribute für dieses Element enthält.

ChildElements

Ruft alle untergeordneten Elemente des aktuellen Elements ab.

ElementTagName

Stellt ein Element in einer Konfigurationsdatei dar.

IsLocallyStored

Ruft einen Wert ab, der angibt, ob das Konfigurationselement in einer bestimmten Konfigurationsdatei gespeichert ist.

Item[String]

Ruft ein Attribut mit dem angegebenen Namen ab oder legt es fest.

Methods

Ruft eine Auflistung von Methoden für das Konfigurationselement ab.

RawAttributes

Stellt ein Element in einer Konfigurationsdatei dar.

Schema

Ruft das Schema für das aktuelle Element ab.

Methoden

Delete()

Stellt ein Element in einer Konfigurationsdatei dar.

GetAttribute(String)

Gibt ein ConfigurationAttribute -Objekt zurück, das das angeforderte Attribut darstellt.

GetAttributeValue(String)

Gibt den Wert des angegebenen Attributs zurück.

GetChildElement(String)

Gibt ein untergeordnetes Element zurück, das sich unter dem aktuellen Konfigurationselement befindet und den angegebenen Namen hat.

GetChildElement(String, Type)

Gibt ein untergeordnetes Element zurück, das sich unter dem aktuellen Konfigurationselement befindet und den angegebenen Namen und Typ aufweist.

GetCollection()

Gibt die Standardauflistung für das aktuelle Konfigurationselement zurück.

GetCollection(String)

Gibt alle Konfigurationselemente zurück, die zum aktuellen Konfigurationselement gehören.

GetCollection(String, Type)

Gibt das Konfigurationselement zurück, das über den angegebenen Namen und Typ verfügt und sich unter dem aktuellen Konfigurationselement befindet.

GetCollection(Type)

Gibt das Konfigurationselement zurück, das über den angegebenen Typ verfügt und sich unter dem aktuellen Konfigurationselement befindet.

GetMetadata(String)

Gibt Metadatenwerte aus dem Elementschema zurück.

SetAttributeValue(String, Object)

Legt den Wert des angegebenen Attributs fest.

SetMetadata(String, Object)

Legt Metadatenwerte aus dem Elementschema fest.

Gilt für: