다음을 통해 공유


ConfigurationElement 클래스

정의

구성 파일의 요소를 나타냅니다.

public ref class ConfigurationElement
public class ConfigurationElement
type ConfigurationElement = class
Public Class ConfigurationElement
상속
ConfigurationElement
파생

예제

다음 예제에서는 클래스의 여러 메서드 및 속성을 구현합니다 ConfigurationElement . 이 예제에서는 섹션에 ConfigurationSection 대한 개체를 moduleProvider 가져오고 해당 섹션에서 을 ConfigurationElementCollection 가져옵니다. 이 예제에서는 검색된 각 ConfigurationElement 컬렉션을 반복합니다.

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

설명

섹션의 구성 섹션, 컬렉션 항목 및 중첩된 요소를 포함하여 많은 구성 엔터티의 기본 클래스입니다.

생성자

ConfigurationElement()

ConfigurationElement 클래스의 새 인스턴스를 초기화합니다.

속성

Attributes

이 요소에 대한 특성 목록을 포함하는 구성 특성 컬렉션을 가져옵니다.

ChildElements

현재 요소의 모든 자식 요소를 가져옵니다.

ElementTagName

구성 파일의 요소를 나타냅니다.

IsLocallyStored

구성 요소가 특정 구성 파일에 저장되어 있는지 여부를 나타내는 값을 가져옵니다.

Item[String]

지정된 이름의 특성을 가져오거나 설정합니다.

Methods

구성 요소에 대한 메서드 컬렉션을 가져옵니다.

RawAttributes

구성 파일의 요소를 나타냅니다.

Schema

현재 요소의 스키마를 가져옵니다.

메서드

Delete()

구성 파일의 요소를 나타냅니다.

GetAttribute(String)

요청된 ConfigurationAttribute 특성을 나타내는 개체를 반환합니다.

GetAttributeValue(String)

지정된 특성의 값을 반환합니다.

GetChildElement(String)

현재 구성 요소 아래에 있고 지정된 이름을 가진 자식 요소를 반환합니다.

GetChildElement(String, Type)

현재 구성 요소 아래에 있고 지정된 이름과 형식을 가진 자식 요소를 반환합니다.

GetCollection()

현재 구성 요소의 기본 컬렉션을 반환합니다.

GetCollection(String)

현재 구성 요소에 속하는 모든 구성 요소를 반환합니다.

GetCollection(String, Type)

지정된 이름과 형식을 가지며 현재 구성 요소 아래에 있는 구성 요소를 반환합니다.

GetCollection(Type)

지정된 형식을 가지며 현재 구성 요소 아래에 있는 구성 요소를 반환합니다.

GetMetadata(String)

요소 스키마에서 메타데이터 값을 반환합니다.

SetAttributeValue(String, Object)

지정된 특성의 값을 설정합니다.

SetMetadata(String, Object)

요소 스키마에서 메타데이터 값을 설정합니다.

적용 대상