ConfigurationElementCollection.CreateNewElement(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立目前集合的新專案。
protected:
override Microsoft::Web::Administration::ConfigurationElement ^ CreateNewElement(System::String ^ elementTagName);
protected override Microsoft.Web.Administration.ConfigurationElement CreateNewElement (string elementTagName);
override this.CreateNewElement : string -> Microsoft.Web.Administration.ConfigurationElement
Protected Overrides Function CreateNewElement (elementTagName As String) As ConfigurationElement
參數
- elementTagName
- String
要建立的項目名稱。
傳回
已建立之新 ConfigurationElement 物件的參考。
範例
下列範例示範 CreateNewElement 方法。 本範例會設定數個屬性值,並將新建立的專案加入至專案集合。 此程式碼範例是提供給 類別之較大範例的 ConfigurationElement 一部分。
// Use any of the following lines to set the attribute value.
// attribute.Value = "TestDemo(Modified)";
moduleproviderelement.SetAttributeValue(
"name", "TestDemo(Modified)");
// moduleproviderelement["name"] = "TestDemo(Modified)";
備註
CreateNewElement覆寫 方法來建立特定類型的自訂 ConfigurationElement 物件。 從組態檔載入集合時, CreateNewElement 會呼叫 來建立個別專案。 CreateNewElement 必須在衍生自 類別的 ConfigurationElementCollection 類別中覆寫。
建立專案之後,必須設定元素的屬性,而且元素必須加入至專案集合。
當組態專案新增至 物件, ConfigurationElementCollection 並使用 方法更新 Update 時,它會儲存在Administration.config檔案中。
建立組態專案時,必須使用唯一的名稱屬性加以建立。 如果 name 屬性不是唯一的,就會發生錯誤。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應