ConfigurationSection.GetRuntimeObject 方法

定義

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

protected:
 virtual System::Object ^ GetRuntimeObject();
protected public:
 virtual System::Object ^ GetRuntimeObject();
protected virtual object GetRuntimeObject ();
protected internal virtual object GetRuntimeObject ();
abstract member GetRuntimeObject : unit -> obj
override this.GetRuntimeObject : unit -> obj
Protected Overridable Function GetRuntimeObject () As Object
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 作的方法。

適用於