ConfigurationSection.GetRuntimeObject 方法

定義

在衍生類別中覆寫時,會回傳一個自訂物件。

protected public:
 virtual System::Object ^ GetRuntimeObject();
protected internal virtual object GetRuntimeObject();
abstract member GetRuntimeObject : unit -> obj
override this.GetRuntimeObject : unit -> obj
Protected Friend Overridable Function GetRuntimeObject () As Object

傳回

代表該區域的物件。

範例

以下範例說明如何使用此 GetRuntimeObject 方法。

// Customizes the use of CustomSection
// by setting _ReadOnly to false.
// Remember you must use it along with ThrowIfReadOnly.
protected override object GetRuntimeObject()
{
    // To enable property setting just assign true to
    // the following flag.
    _ReadOnly = true;
    return base.GetRuntimeObject();
}
' Customizes the use of CustomSection
 ' by setting _ReadOnly to false.
' Remember you must use it along with ThrowIfReadOnly.
Protected Overrides Function GetRuntimeObject() As Object
   ' To enable property setting just assign true to
   ' the following flag.
   _ReadOnly = True
   Return MyBase.GetRuntimeObject()
End Function 'GetRuntimeObject

備註

當執行時呼叫該 GetSection 方法時,組態系統會先建立適當的類別實例 ConfigurationSection ,然後回傳從該 GetRuntimeObject 方法取得的物件。

預設情況下,會 GetRuntimeObject 直接回傳代表其被呼叫來源的 ConfigurationSection 物件。

給繼承者的注意事項

你可以覆寫 GetRuntimeObject() 執行時回傳自訂型的方法。

例如,為了限制類別中設定的執行時修改 ConfigurationSection ,你可以覆寫 GetRuntimeObject() 並回傳自訂型別,強制限制哪些設定可以修改。

如果執行時物件僅為內部物件,則回傳物件無法在定義它的組件外使用。 建立一個物件,該物件源自 ConfigurationSection 組合語言且只能在執行時被程式碼存取,一種方法是建立一個內部執行時物件,裡面有一個回傳你 ConfigurationSection 實作的方法。

適用於