語言

CustomErrorCollection.Clear 方法

定義

移除收藏中的所有 CustomError 物件。

public:
 void Clear();
public void Clear();
member this.Clear : unit -> unit
Public Sub Clear ()

範例

以下程式碼範例將移除集合中CustomError的所有CustomErrorCollection物件。 參考課堂主題中的 CustomErrorCollection 程式碼範例,學習如何取得該集合。

// Using the Clear method.
if (!customErrorsSection.SectionInformation.IsLocked)
{
    // Execute the Clear method.
    customErrorsCollection.Clear();
    configuration.Save();
}
' Using the Clear method.
If Not customErrorsSection.SectionInformation.IsLocked Then
   ' Execute the Clear method.
   customErrorsCollection.Clear()
   configuration.Save()
End If

備註

呼叫 Clear 該方法後更新設定檔的結果取決於所選擇的方法 ConfigurationSaveMode 。 要更新設定檔,你會使用以下兩種超載之一: Save 和 Save。

Note

呼叫 Save 就相當於呼叫 Save。

如果你使用 Save.method,會適用以下條件。

  • 如果你傳遞一個 Full or Modified 參數值,那麼在當前階層層級的設定檔區段中會插入clear一個clientTarget元素。

  • 若您傳遞 Minimal 參數值,則在當前階層層級的組態檔案中,會加入一系列 remove 元素,並加到配置檔的 clientTarget Element(ASP.NET 設定架構)。 每個 Reference 都會移除階層 add 結構中父組態檔案中定義元素的所有參考。 當你使用 Minimal時,集合上還有一個額外的屬性會影響設定檔序列化的內容: EmitClear,預設是 false 序列化的。 適用條件如下。

    • 若設 EmitClear 為 true, clear 則在當前階層層級的配置檔區段中插入 clientTarget 元素。 此舉移除階層結構中父組態檔案中定義元素的所有參考 add 。

    • 若 EmitClear 將旗標設為 false, clear 該元素會從目前階層層級的設定檔案區塊中移除 clientTarget (若存在)。

此 Clear 方法實際上會 add 刪除設定檔中當前階層層級中定義 clientTarget 的元素。 它也會移除階層結構中父組態檔案中定義的 add 元素的所有參考。

Note

add這些元素不會從clientTarget父組態檔案的區塊中刪除。

適用於