ConfigurationElement 类

定义

表示配置文件中的配置元素。Represents a configuration element within a configuration file.

public ref class ConfigurationElement abstract
public abstract class ConfigurationElement
type ConfigurationElement = class
Public MustInherit Class ConfigurationElement
继承
ConfigurationElement
派生

示例

下面的代码示例演示如何将自定义 ConfigurationElement 既实现为自定义节中的单个元素,也可作为自定义节中的元素集合。The following code example shows how to implement a custom ConfigurationElement both as an individual element in a custom section and as a collection of elements in a custom section. 该示例包含以下文件:The example consists of the following files:

  • App.config 文件,其中包含名为 MyUrls 的自定义部分。An app.config file that contains a custom section that is named MyUrls. 本部分包含一个简单元素(不包含任何其他元素)和一个元素集合。This section contains a simple element (it does not contain any other elements) and a collection of elements. 简单元素被命名为 simple,集合命名为 urlsThe simple element is named simple and the collection is named urls.

  • 控制台应用程序。A console application. 应用程序读取 app.config 文件的内容,并将信息写入控制台。The application reads the contents of the app.config file and writes the information to the console. 它使用从 ConfigurationElementConfigurationElementCollectionConfigurationSection 派生的类。It uses classes that derive from ConfigurationElement, ConfigurationElementCollection, and ConfigurationSection.

  • 从 @no__t 类派生的名为 UrlsSection 的类。A class named UrlsSection that derives from the ConfigurationSection class. 此类用于访问配置文件中的 @no__t 0 部分。This class is used to access the MyUrls section in the configuration file.

  • 从 @no__t 类派生的名为 UrlsCollection 的类。A class named UrlsCollection that derives from the ConfigurationElementCollection class. 此类用于访问配置文件中的 @no__t 集合。This class is used to access the urls collection in the configuration file.

  • 从 @no__t 类派生的名为 UrlConfigElement 的类。A class named UrlConfigElement that derives from the ConfigurationElement class. 此类用于访问配置文件中的 @no__t 0 元素和 @no__t 集合的成员。This class is used to access the simple element and the members of the urls collection in the configuration file.

若要运行该示例,请执行以下步骤:To run the example, perform the following steps:

  1. 创建一个解决方案,其中包含一个控制台应用程序项目和一个名为 ConfigurationElement 的类库项目。Create a solution that has a console application project and a class library project that is named ConfigurationElement.

  2. 将三个类文件放在类库项目中,并将其他文件放在控制台库项目中。Put the three class files in the class library project and put the other files in the console library project.

  3. 在这两个项目中,将引用设置为 System.ConfigurationIn both projects set a reference to System.Configuration.

  4. 在控制台应用程序项目中,将项目引用设置为类库项目。In the console application project set a project reference to the class library project.

// Set Assembly name to ConfigurationElement
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    // Entry point for console application that reads the 
    // app.config file and writes to the console the 
    // URLs in the custom section.  
    class TestConfigurationElement
    {
        static void Main(string[] args)
        {
            // Get current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

            // Get the MyUrls section.
            UrlsSection myUrlsSection =
                config.GetSection("MyUrls") as UrlsSection;

            if (myUrlsSection == null)
                Console.WriteLine("Failed to load UrlsSection.");
            else
            {
                Console.WriteLine("The 'simple' element of app.config:");
                Console.WriteLine("  Name={0} URL={1} Port={2}",
                    myUrlsSection.Simple.Name,
                    myUrlsSection.Simple.Url,
                    myUrlsSection.Simple.Port);

                Console.WriteLine("The urls collection of app.config:");
                for (int i = 0; i < myUrlsSection.Urls.Count; i++)
                {
                    Console.WriteLine("  Name={0} URL={1} Port={2}",
                        myUrlsSection.Urls[i].Name,
                        myUrlsSection.Urls[i].Url,
                        myUrlsSection.Urls[i].Port);
                }
            }
            Console.ReadLine();
        }
    }
}
' Set Assembly name to ConfigurationElement
' and set Root namespace to Samples.AspNet
Imports System.Configuration
Imports System.Collections

Class TestConfigurationElement
    ' Entry point for console application that reads the 
    ' app.config file and writes to the console the 
    ' URLs in the custom section.
    Shared Sub Main(ByVal args() As String)
        ' Get the current configuration file.
        Dim config As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            ConfigurationUserLevel.None)

        ' Get the MyUrls section.
        Dim myUrlsSection As UrlsSection = _
            config.GetSection("MyUrls")

        If myUrlsSection Is Nothing Then
            Console.WriteLine("Failed to load UrlsSection.")
        Else
            Console.WriteLine("The 'simple' element of app.config:")
            Console.WriteLine("  Name={0} URL={1} Port={2}", _
                myUrlsSection.Simple.Name, _
                myUrlsSection.Simple.Url, _
                myUrlsSection.Simple.Port)
            Console.WriteLine("The urls collection of app.config:")
            Dim i As Integer
            For i = 0 To myUrlsSection.Urls.Count - 1
                Console.WriteLine("  Name={0} URL={1} Port={2}", _
                i, myUrlsSection.Urls(i).Name, _
                myUrlsSection.Urls(i).Url, _
                myUrlsSection.Urls(i).Port)
            Next i
        End If
        Console.ReadLine()
    End Sub
End Class
using System;
using System.Configuration;
using System.Collections;


namespace Samples.AspNet
{
    // Define a custom section containing an individual
    // element and a collection of elements.
    public class UrlsSection : ConfigurationSection
    {
        [ConfigurationProperty("name", 
            DefaultValue = "MyFavorites",
            IsRequired = true, 
            IsKey = false)]
        [StringValidator(InvalidCharacters = 
            " ~!@#$%^&*()[]{}/;'\"|\\",
            MinLength = 1, MaxLength = 60)]
        public string Name
        {

            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }

        }

        // Declare an element (not in a collection) of the type
        // UrlConfigElement. In the configuration
        // file it corresponds to <simple .... />.
        [ConfigurationProperty("simple")]
        public UrlConfigElement Simple
        {
            get
            {
                UrlConfigElement url =
                (UrlConfigElement)base["simple"];
                return url;
            }
        }

        // Declare a collection element represented 
        // in the configuration file by the sub-section
        // <urls> <add .../> </urls> 
        // Note: the "IsDefaultCollection = false" 
        // instructs the .NET Framework to build a nested 
        // section like <urls> ...</urls>.
        [ConfigurationProperty("urls",
            IsDefaultCollection = false)]
        public UrlsCollection Urls
        {
            get
            {
                UrlsCollection urlsCollection =
                (UrlsCollection)base["urls"];
                return urlsCollection;
            }
        }


        protected override void DeserializeSection(
            System.Xml.XmlReader reader)
        {
            base.DeserializeSection(reader);
            // You can add custom processing code here.
        }

        protected override string SerializeSection(
            ConfigurationElement parentElement,
            string name, ConfigurationSaveMode saveMode)
        {
            string s =
                base.SerializeSection(parentElement,
                name, saveMode);
            // You can add custom processing code here.
            return s;
        }

    }
}
Imports System.Configuration
Imports System.Collections

' Define a custom section containing an individual
' element and a collection of elements.
Public Class UrlsSection
    Inherits ConfigurationSection

    <ConfigurationProperty("name", _
        DefaultValue:="MyFavorites", _
        IsRequired:=True, _
        IsKey:=False), _
        StringValidator( _
        InvalidCharacters:=" ~!@#$%^&*()[]{}/;'""|\", _
        MinLength:=1, MaxLength:=60)> _
        Public Property Name() As String

        Get
            Return CStr(Me("name"))
        End Get
        Set(ByVal value As String)
            Me("name") = value
        End Set
    End Property
    
    ' Declare an element (not in a collection) of the type
    ' UrlConfigElement. In the configuration
    ' file it corresponds to <simple .... />.
    <ConfigurationProperty("simple")> _
        Public ReadOnly Property Simple() _
        As UrlConfigElement

        Get
            Dim url As UrlConfigElement = _
                CType(Me("simple"),  _
                UrlConfigElement)
            Return url
        End Get
    End Property
    
    ' Declare a collection element represented 
    ' in the configuration file by the sub-section
    ' <urls> <add .../> </urls> 
    ' Note: the "IsDefaultCollection = false" 
    ' instructs the .NET Framework to build a nested 
    ' section like <urls> ...</urls>.
    <ConfigurationProperty("urls", _
        IsDefaultCollection:=False)> _
        Public ReadOnly Property Urls() _
        As UrlsCollection

        Get
            Dim urlsCollection _
                As UrlsCollection = _
                CType(Me("urls"), UrlsCollection)
            Return urlsCollection
        End Get
    End Property

    Protected Overrides Sub DeserializeSection( _
        ByVal reader As System.Xml.XmlReader)

        MyBase.DeserializeSection(reader)
        ' Enter your custom processing code here.
    End Sub

    Protected Overrides Function SerializeSection( _
        ByVal parentElement As ConfigurationElement, _
        ByVal name As String, _
        ByVal saveMode As ConfigurationSaveMode) As String

        Dim s As String = _
            MyBase.SerializeSection(parentElement, _
            name, saveMode)
        ' Enter your custom processing code here.
        Return s
    End Function 'SerializeSection
End Class
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    public class UrlsCollection : ConfigurationElementCollection
    {
        public UrlsCollection()
        {
            // Add one url to the collection.  This is
            // not necessary; could leave the collection 
            // empty until items are added to it outside
            // the constructor.
            UrlConfigElement url = 
                (UrlConfigElement)CreateNewElement();
            Add(url);
        }

        public override 
            ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return 

                    ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override 
            ConfigurationElement CreateNewElement()
        {
            return new UrlConfigElement();
        }


        protected override 
            ConfigurationElement CreateNewElement(
            string elementName)
        {
            return new UrlConfigElement(elementName);
        }


        protected override Object 
            GetElementKey(ConfigurationElement element)
        {
            return ((UrlConfigElement)element).Name;
        }


        public new string AddElementName
        {
            get
            { return base.AddElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string ClearElementName
        {
            get
            { return base.ClearElementName; }

            set
            { base.ClearElementName = value; }

        }

        public new string RemoveElementName
        {
            get
            { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }


        public UrlConfigElement this[int index]
        {
            get
            {
                return (UrlConfigElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public UrlConfigElement this[string Name]
        {
            get
            {
                return (UrlConfigElement)BaseGet(Name);
            }
        }

        public int IndexOf(UrlConfigElement url)
        {
            return BaseIndexOf(url);
        }

        public void Add(UrlConfigElement url)
        {
            BaseAdd(url);
            // Add custom code here.
        }

        protected override void 
            BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
            // Add custom code here.
        }

        public void Remove(UrlConfigElement url)
        {
            if (BaseIndexOf(url) >= 0)
                BaseRemove(url.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
            // Add custom code here.
        }
    }
}
Imports System.Configuration
Imports System.Collections

Public Class UrlsCollection
    Inherits ConfigurationElementCollection

    Public Sub New()
        ' Add one url to the collection.  This is
        ' not necessary; could leave the collection 
        ' empty until items are added to it outside
        ' the constructor.
        Dim url As UrlConfigElement = _
            CType(CreateNewElement(), UrlConfigElement)
        ' Add the element to the collection.
        Add(url)
    End Sub

    Public Overrides ReadOnly Property CollectionType() _
        As ConfigurationElementCollectionType

        Get
            Return ConfigurationElementCollectionType.AddRemoveClearMap
        End Get
    End Property

    Protected Overloads Overrides Function CreateNewElement() _
        As ConfigurationElement

        Return New UrlConfigElement()
    End Function 'CreateNewElement

    Protected Overloads Overrides Function CreateNewElement( _
        ByVal elementName As String) _
        As ConfigurationElement

        Return New UrlConfigElement(elementName)
    End Function 'CreateNewElement

    Protected Overrides Function GetElementKey( _
        ByVal element As ConfigurationElement) As [Object]

        Return CType(element, UrlConfigElement).Name
    End Function 'GetElementKey

    Public Shadows Property AddElementName() As String

        Get
            Return MyBase.AddElementName
        End Get

        Set(ByVal value As String)
            MyBase.AddElementName = value
        End Set
    End Property

    Public Shadows Property ClearElementName() As String
        Get
            Return MyBase.ClearElementName
        End Get

        Set(ByVal value As String)
            MyBase.ClearElementName = value
        End Set
    End Property

    Public Shadows ReadOnly Property RemoveElementName() As String
        Get
            Return MyBase.RemoveElementName
        End Get
    End Property

    Public Shadows ReadOnly Property Count() As Integer
        Get
            Return MyBase.Count
        End Get
    End Property

    Default Public Shadows Property Item( _
    ByVal index As Integer) As UrlConfigElement
        Get
            Return CType(BaseGet(index), UrlConfigElement)
        End Get

        Set(ByVal value As UrlConfigElement)
            If Not (BaseGet(index) Is Nothing) Then
                BaseRemoveAt(index)
            End If
            BaseAdd(index, value)
        End Set
    End Property

    Default Public Shadows ReadOnly Property Item( _
        ByVal Name As String) As UrlConfigElement

        Get
            Return CType(BaseGet(Name), UrlConfigElement)
        End Get
    End Property

    Public Function IndexOf( _
        ByVal url As UrlConfigElement) As Integer

        Return BaseIndexOf(url)
    End Function 'IndexOf

    Public Sub Add(ByVal url As UrlConfigElement)
        BaseAdd(url)
        ' Add custom code here.
    End Sub

    Protected Overrides Sub BaseAdd( _
    ByVal element As ConfigurationElement)
        BaseAdd(element, False)
        ' Add custom code here.
    End Sub

    Public Overloads Sub Remove( _
        ByVal url As UrlConfigElement)

        If BaseIndexOf(url) >= 0 Then
            BaseRemove(url.Name)
        End If
    End Sub

    Public Sub RemoveAt(ByVal index As Integer)
        BaseRemoveAt(index)
    End Sub

    Public Overloads Sub Remove(ByVal name As String)
        BaseRemove(name)
    End Sub

    Public Sub Clear()
        BaseClear()
    End Sub
End Class
using System;
using System.Configuration;
using System.Collections;

namespace Samples.AspNet
{
    public class UrlConfigElement : ConfigurationElement
    {
        // Constructor allowing name, url, and port to be specified.
        public UrlConfigElement(String newName,
            String newUrl, int newPort)
        {
            Name = newName;
            Url = newUrl;
            Port = newPort;
        }

        // Default constructor, will use default values as defined
        // below.
        public UrlConfigElement()
        {
        }

        // Constructor allowing name to be specified, will take the
        // default values for url and port.
        public UrlConfigElement(string elementName)
        {
            Name = elementName;
        }

        [ConfigurationProperty("name", 
            DefaultValue = "Microsoft",
            IsRequired = true, 
            IsKey = true)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        [ConfigurationProperty("url",
            DefaultValue = "http://www.microsoft.com",
            IsRequired = true)]
        [RegexStringValidator(@"\w+:\/\/[\w.]+\S*")]
        public string Url
        {
            get
            {
                return (string)this["url"];
            }
            set
            {
                this["url"] = value;
            }
        }

        [ConfigurationProperty("port",
            DefaultValue = (int)0,
            IsRequired = false)]
        [IntegerValidator(MinValue = 0,
            MaxValue = 8080, ExcludeRange = false)]
        public int Port
        {
            get
            {
                return (int)this["port"];
            }
            set
            {
                this["port"] = value;
            }
        }

        protected override void DeserializeElement(
           System.Xml.XmlReader reader, 
            bool serializeCollectionKey)
        {
            base.DeserializeElement(reader, 
                serializeCollectionKey);
            // You can your custom processing code here.
        }


        protected override bool SerializeElement(
            System.Xml.XmlWriter writer, 
            bool serializeCollectionKey)
        {
            bool ret = base.SerializeElement(writer, 
                serializeCollectionKey);
            // You can enter your custom processing code here.
            return ret;

        }


        protected override bool IsModified()
        {
            bool ret = base.IsModified();
            // You can enter your custom processing code here.
            return ret;
        }
    }
}
Imports System.Configuration
Imports System.Collections

Public Class UrlConfigElement
    Inherits ConfigurationElement

    ' Constructor allowing name, url, and port to be specified.
    Public Sub New(ByVal newName As String, _
        ByVal newUrl As String, _
        ByVal newPort As Integer)

        Name = newName
        Url = newUrl
        Port = newPort

    End Sub

    ' Default constructor, will use default values as defined
    Public Sub New()

    End Sub


    ' Constructor allowing name to be specified, will take the
    ' default values for url and port.
    Public Sub New(ByVal elementName As String)
        Name = elementName

    End Sub


    <ConfigurationProperty("name", _
        DefaultValue:="Microsoft", _
        IsRequired:=True, _
        IsKey:=True)> _
        Public Property Name() As String

        Get
            Return CStr(Me("name"))
        End Get
        Set(ByVal value As String)
            Me("name") = value
        End Set
    End Property


    <ConfigurationProperty("url", _
        DefaultValue:="http://www.microsoft.com", _
        IsRequired:=True), _
        RegexStringValidator("\w+:\/\/[\w.]+\S*")> _
        Public Property Url() As String

        Get
            Return CStr(Me("url"))
        End Get
        Set(ByVal value As String)
            Me("url") = value
        End Set
    End Property


    <ConfigurationProperty("port", _
        DefaultValue:=0, _
        IsRequired:=False), _
        IntegerValidator(MinValue:=0, _
        MaxValue:=8080, ExcludeRange:=False)> _
        Public Property Port() As Integer

        Get
            Return Fix(Me("port"))
        End Get
        Set(ByVal value As Integer)
            Me("port") = value
        End Set
    End Property


    Protected Overrides Sub DeserializeElement(ByVal reader _
        As System.Xml.XmlReader, _
        ByVal serializeCollectionKey As Boolean)

        MyBase.DeserializeElement(reader, _
            serializeCollectionKey)
        ' Enter your custom processing code here.
    End Sub

    Protected Overrides Function SerializeElement(ByVal writer _
        As System.Xml.XmlWriter, _
        ByVal serializeCollectionKey As Boolean) As Boolean

        Dim ret As Boolean = _
            MyBase.SerializeElement(writer, serializeCollectionKey)
        ' Enter your custom processing code here.
        Return ret
    End Function 'SerializeElement

    Protected Overrides Function IsModified() As Boolean
        Dim ret As Boolean = MyBase.IsModified()
        ' Enter your custom processing code here.
        Return ret

    End Function 'IsModified
End Class

注解

@No__t-0 是一个抽象类,用于表示配置文件(如 web.config)中的 XML 元素。The ConfigurationElement is an abstract class that is used to represent an XML element in a configuration file (such as Web.config). 配置文件中的元素可包含零个、一个或多个子元素。An element in a configuration file can contain zero, one, or more child elements.

由于 @no__t 0 类定义为抽象类,因此不能创建它的实例。Because the ConfigurationElement class is defined as abstract, you cannot create an instance of it. 只能从中派生类。You can only derive classes from it. .NET Framework 包括从 ConfigurationElement 类派生的类,以表示标准 XML 配置元素,如 ConfigurationSectionThe .NET Framework includes classes that derive from the ConfigurationElement class in order to represent standard XML configuration elements, such as ConfigurationSection. 还可以扩展 @no__t 0 类,以访问自定义配置元素和节。You can also extend the ConfigurationElement class to access custom configuration elements and sections. 本主题后面的示例演示如何使用派生自 @no__t 的自定义类来访问自定义配置元素和节。The example included later in this topic shows how to access custom configuration elements and sections by using custom classes that derive from ConfigurationElement.

你还可以扩展标准配置类型,例如 ConfigurationElementConfigurationElementCollectionConfigurationProperty 和 @no__t。You can also extend the standard configuration types such as ConfigurationElement, ConfigurationElementCollection, ConfigurationProperty, and ConfigurationSection. 有关详细信息,请参阅这些类的文档。For more information, see the documentation for those classes.

有关如何访问配置文件中的信息的详细信息,请参阅 ConfigurationManager 类和 @no__t。For more information about how to access information in configuration files, see the ConfigurationManager class and the WebConfigurationManager class.

实施者说明

ConfigurationElement 对象都会创建一个 ConfigurationProperty 对象的内部 @no__t 集合,该集合表示元素特性或子元素的集合。Every ConfigurationElement object creates an internal ConfigurationPropertyCollection collection of ConfigurationProperty objects that represents either the element attributes or a collection of child elements.

不可自定义的信息和功能由 ElementInformation 属性提供的 @no__t 0 对象所包含。Non-customizable information and functionality is contained by an ElementInformation object provided by the ElementInformation property.

您可以使用编程或声明性(特性化)编码模型创建自定义配置元素:You can use either a programmatic or a declarative (attributed) coding model to create a custom configuration element: -编程模型要求每个元素特性都创建一个属性以获取或设置其值,并将其添加到基础 ConfigurationElement 基类的内部属性包。- The programmatic model requires that for each element attribute, you create a property to get or set its value and add it to the internal property bag of the underlying ConfigurationElement base class. 有关如何使用此模型的示例,请参阅 ConfigurationSection 类。For an example of how to use this model, see the ConfigurationSection class.

-更简单的声明性模型(也称为特性化模型)允许您通过使用属性来定义元素特性,然后使用特性修饰它。- The simpler declarative model, also called the attributed model, allows you to define an element attribute by using a property and then decorate it with attributes. 这些属性指示 ASP.NET 配置系统有关属性类型及其默认值的信息。These attributes instruct the ASP.NET configuration system about the property types and their default values. 通过反射获取此信息,ASP.NET 配置系统会为您创建元素属性对象并执行所需的初始化。With this information, obtained through reflection, the ASP.NET configuration system creates the element property objects for you and performs the required initialization. 本主题后面显示的示例演示如何使用此模型。The example shown later in this topic shows how to use this model.

构造函数

ConfigurationElement()

初始化 ConfigurationElement 类的新实例。Initializes a new instance of the ConfigurationElement class.

属性

CurrentConfiguration

获取对顶级 Configuration 实例的引用,该实例表示当前 ConfigurationElement 实例所属的配置层次结构。Gets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to.

ElementInformation

获取包含 ConfigurationElement 对象的不可自定义的信息和功能的 ElementInformation 对象。Gets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object.

ElementProperty

获取表示 ConfigurationElement 对象本身的 ConfigurationElementProperty 对象。Gets the ConfigurationElementProperty object that represents the ConfigurationElement object itself.

EvaluationContext

获取 ConfigurationElement 对象的 ContextInformation 对象。Gets the ContextInformation object for the ConfigurationElement object.

HasContext

获取一个值,该值指示 CurrentConfiguration 属性是否为 nullGets a value that indicates whether the CurrentConfiguration property is null.

Item[ConfigurationProperty]

获取或设置此配置元素的属性或特性。Gets or sets a property or attribute of this configuration element.

Item[String]

获取或设置此配置元素的属性、特性或子元素。Gets or sets a property, attribute, or child element of this configuration element.

LockAllAttributesExcept

获取被锁定的特性的集合。Gets the collection of locked attributes.

LockAllElementsExcept

获取被锁定的元素的集合。Gets the collection of locked elements.

LockAttributes

获取被锁定的特性的集合。Gets the collection of locked attributes.

LockElements

获取被锁定的元素的集合。Gets the collection of locked elements.

LockItem

获取或设置一个值,该值指示是否已锁定该元素。Gets or sets a value indicating whether the element is locked.

Properties

获取属性的集合。Gets the collection of properties.

方法

DeserializeElement(XmlReader, Boolean)

从配置文件读取 XML。Reads XML from the configuration file.

Equals(Object)

将当前的 ConfigurationElement 实例与指定的对象进行比较。Compares the current ConfigurationElement instance to the specified object.

GetHashCode()

获取表示当前 ConfigurationElement 实例的唯一值。Gets a unique value representing the current ConfigurationElement instance.

GetTransformedAssemblyString(String)

返回指定程序集名称的转换版本。Returns the transformed version of the specified assembly name.

GetTransformedTypeString(String)

返回指定类型名称的转换版本。Returns the transformed version of the specified type name.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Init()

ConfigurationElement 对象设置为其初始状态。Sets the ConfigurationElement object to its initial state.

InitializeDefault()

用于初始化 ConfigurationElement 对象的默认值集。Used to initialize a default set of values for the ConfigurationElement object.

IsModified()

指示自上次保存或加载该配置元素后并在派生类中实现该元素时,该元素是否已被修改。Indicates whether this configuration element has been modified since it was last saved or loaded, when implemented in a derived class.

IsReadOnly()

获取一个值,该值指示 ConfigurationElement 对象是否为只读。Gets a value indicating whether the ConfigurationElement object is read-only.

ListErrors(IList)

将此 ConfigurationElement 对象以及所有子元素中无效属性的错误添加到传递的列表中。Adds the invalid-property errors in this ConfigurationElement object, and in all subelements, to the passed list.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnDeserializeUnrecognizedAttribute(String, String)

获取一个值,该值指示反序列化过程中是否遇到未知特性。Gets a value indicating whether an unknown attribute is encountered during deserialization.

OnDeserializeUnrecognizedElement(String, XmlReader)

获取一个值,该值指示反序列化过程中是否遇到未知元素。Gets a value indicating whether an unknown element is encountered during deserialization.

OnRequiredPropertyNotFound(String)

找不到所需属性时引发异常。Throws an exception when a required property is not found.

PostDeserialize()

反序列化后调用。Called after deserialization.

PreSerialize(XmlWriter)

在序列化之前调用。Called before serialization.

Reset(ConfigurationElement)

重置 ConfigurationElement 对象的内部状态,包括锁和属性集合。Resets the internal state of the ConfigurationElement object, including the locks and the properties collections.

ResetModified()

在派生类中实现时,将 IsModified() 方法的值重置为 falseResets the value of the IsModified() method to false when implemented in a derived class.

SerializeElement(XmlWriter, Boolean)

当在派生类中实现后,将此配置元素的内容写入配置文件。Writes the contents of this configuration element to the configuration file when implemented in a derived class.

SerializeToXmlElement(XmlWriter, String)

当在派生类中实现后,将此配置元素的外部标记写入配置文件。Writes the outer tags of this configuration element to the configuration file when implemented in a derived class.

SetPropertyValue(ConfigurationProperty, Object, Boolean)

将属性设置为指定值。Sets a property to the specified value.

SetReadOnly()

设置 ConfigurationElement 对象及所有子元素的 IsReadOnly() 属性。Sets the IsReadOnly() property for the ConfigurationElement object and all subelements.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

修改 ConfigurationElement 对象以移除所有不应该保存的值。Modifies the ConfigurationElement object to remove all values that should not be saved.

适用于

另请参阅