ConfigurationElementCollection.CreateNewElement 方法

定义

在派生的类中重写时,创建一个新的 ConfigurationElement

重载

CreateNewElement(String)

在派生的类中重写时,创建新的 ConfigurationElement

CreateNewElement()

在派生的类中重写时,创建一个新的 ConfigurationElement

注解

CreateNewElement重写 方法以创建特定类型的自定义ConfigurationElement对象。 从配置文件加载集合时, CreateNewElement 调用 以创建单个元素。 CreateNewElement 必须在派生自 ConfigurationElementCollection 类的类中重写。

CreateNewElement(String)

Source:
ConfigurationElementCollection.cs
Source:
ConfigurationElementCollection.cs
Source:
ConfigurationElementCollection.cs

在派生的类中重写时,创建新的 ConfigurationElement

protected virtual System.Configuration.ConfigurationElement CreateNewElement (string elementName);

参数

elementName
String

要创建的 ConfigurationElement 的名称。

返回

一个新的具有指定名称的 ConfigurationElement

注解

CreateNewElement重写 方法以创建特定类型的自定义ConfigurationElement对象。 从配置文件加载集合时, CreateNewElement 调用 以创建单个元素。 CreateNewElement 必须在派生自 ConfigurationElementCollection 类的类中重写。

继承者说明

如果创建包含异类ConfigurationElement类型的自定义ConfigurationElementCollection集合,则必须执行以下步骤:

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

CreateNewElement()

Source:
ConfigurationElementCollection.cs
Source:
ConfigurationElementCollection.cs
Source:
ConfigurationElementCollection.cs

在派生的类中重写时,创建一个新的 ConfigurationElement

protected abstract System.Configuration.ConfigurationElement CreateNewElement ();

返回

一个新创建的 ConfigurationElement

示例

下面的代码示例演示如何重写 CreateNewElement 方法。

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

注解

CreateNewElement重写 方法以创建特定类型的自定义ConfigurationElement对象。 从配置文件加载集合时, CreateNewElement 调用 以创建单个元素。 CreateNewElement 必须在派生自 ConfigurationElementCollection 类的类中重写。

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9