ConfigurationElementCollection.BaseAdd 方法

定义

在派生的类中重写时,向 ConfigurationElement 实例添加 ConfigurationElementCollectionAdds a ConfigurationElement to an ConfigurationElementCollection instance when overridden in a derived class.

重载

BaseAdd(ConfigurationElement)

ConfigurationElementCollection 添加配置元素。Adds a configuration element to the ConfigurationElementCollection.

BaseAdd(ConfigurationElement, Boolean)

向配置元素集合添加配置元素。Adds a configuration element to the configuration element collection.

BaseAdd(Int32, ConfigurationElement)

向配置元素集合添加配置元素。Adds a configuration element to the configuration element collection.

注解

使用 BaseAdd 方法向集合添加新 ConfigurationElementUse the BaseAdd method to add a new ConfigurationElement to the collection. 如果在添加元素时需要自定义行为,则在派生类中重写。Override in a derived class if custom behavior is required when the element is added.

添加元素时,只有键相同而值不同的元素才被视为重复元素。When adding, an element is considered a duplicate only if the keys are identical but the values are different. 键和值都相同的元素将被接受并且不给出提示,原因是这些元素不会相互竞争。Elements with identical keys and values are accepted silently because the elements do not compete. 但是,无法添加键相同而值不同的元素,因为无法从逻辑上确定哪个竞争值有效。However, an element with an identical key but a different value cannot be added because there is no logic to determine which of the competing values should be honored.

BaseAdd(ConfigurationElement)

ConfigurationElementCollection 添加配置元素。Adds a configuration element to the ConfigurationElementCollection.

protected:
 virtual void BaseAdd(System::Configuration::ConfigurationElement ^ element);
protected virtual void BaseAdd (System.Configuration.ConfigurationElement element);
abstract member BaseAdd : System.Configuration.ConfigurationElement -> unit
override this.BaseAdd : System.Configuration.ConfigurationElement -> unit
Protected Overridable Sub BaseAdd (element As ConfigurationElement)

参数

示例

下面的代码示例演示如何重写 BaseAdd 方法以及如何从 Add 方法中调用它。The following code example shows how to override the BaseAdd method and how to call it from an Add method.

public void Add(UrlConfigElement url)
{
    BaseAdd(url);

    // Your custom code goes here.
}
Public Sub Add(ByVal url As UrlConfigElement)
    BaseAdd(url)

    ' Your custom code goes here.

End Sub

注解

使用 BaseAdd 方法向集合添加新 ConfigurationElementUse the BaseAdd method to add a new ConfigurationElement to the collection. 如果在添加元素时需要自定义行为,请在派生类中重写它。Override it in a derived class if custom behavior is required when the element is added.

添加元素时,只有键相同而值不同的元素才被视为重复元素。When adding, an element is considered a duplicate only if the keys are identical but the values are different. 键和值都相同的元素将被接受并且不给出提示,原因是这些元素不会相互竞争。Elements with identical keys and values are accepted silently because the elements do not compete. 但是,无法添加键相同而值不同的元素,因为无法从逻辑上确定哪个竞争值有效。However, an element with an identical key but a different value cannot be added because there is no logic to determine which of the competing values should be honored.

BaseAdd(ConfigurationElement, Boolean)

向配置元素集合添加配置元素。Adds a configuration element to the configuration element collection.

protected:
 void BaseAdd(System::Configuration::ConfigurationElement ^ element, bool throwIfExists);
protected public:
 void BaseAdd(System::Configuration::ConfigurationElement ^ element, bool throwIfExists);
protected void BaseAdd (System.Configuration.ConfigurationElement element, bool throwIfExists);
protected internal void BaseAdd (System.Configuration.ConfigurationElement element, bool throwIfExists);
member this.BaseAdd : System.Configuration.ConfigurationElement * bool -> unit
Protected Sub BaseAdd (element As ConfigurationElement, throwIfExists As Boolean)
Protected Friend Sub BaseAdd (element As ConfigurationElement, throwIfExists As Boolean)

参数

throwIfExists
Boolean

true 表示如果指定的 ConfigurationElement 已包含在 ConfigurationElementCollection 中则引发异常;否则为 falsetrue to throw an exception if the ConfigurationElement specified is already contained in the ConfigurationElementCollection; otherwise, false.

例外

要添加的 ConfigurationElement 已存在于 ConfigurationElementCollection 中,并且 throwIfExists 参数为 trueThe ConfigurationElement to add already exists in the ConfigurationElementCollection and the throwIfExists parameter is true.

注解

如果 ConfigurationElementCollection 集合中已存在指定的 ConfigurationElement 对象,请使用可选参数 throwIfExists 引发 Exception 异常。Use the optional parameter throwIfExists to throw an Exception exception if the specified ConfigurationElement object already exists in the ConfigurationElementCollection collection.

仅当键相同但值不同时,元素才被视为重复元素。An element is considered a duplicate only if the keys are identical but the values are different. 键和值都相同的元素将被接受并且不给出提示,原因是这些元素不会相互竞争。Elements with identical keys and values are accepted silently because the elements do not compete. 但是,无法添加键相同而值不同的元素,因为无法从逻辑上确定哪个竞争值有效。However, an element with an identical key but a different value cannot be added because there is no logic to determine which of the competing values should be honored.

BaseAdd(Int32, ConfigurationElement)

向配置元素集合添加配置元素。Adds a configuration element to the configuration element collection.

protected:
 virtual void BaseAdd(int index, System::Configuration::ConfigurationElement ^ element);
protected virtual void BaseAdd (int index, System.Configuration.ConfigurationElement element);
abstract member BaseAdd : int * System.Configuration.ConfigurationElement -> unit
override this.BaseAdd : int * System.Configuration.ConfigurationElement -> unit
Protected Overridable Sub BaseAdd (index As Integer, element As ConfigurationElement)

参数

index
Int32

要添加指定 ConfigurationElement 的索引位置。The index location at which to add the specified ConfigurationElement.

注解

使用 index 参数将 ConfigurationElement 对象添加到特定索引位置的 ConfigurationElementCollectionUse the index parameter to add the ConfigurationElement object to the ConfigurationElementCollection at a specific index location.

适用于