ConfigurationSection.GetRuntimeObject メソッド

定義

派生クラスでオーバーライドされると、カスタム オブジェクトを返します。

C#
protected virtual object GetRuntimeObject ();
C#
protected internal virtual object GetRuntimeObject ();

戻り値

セクションを表すオブジェクト。

GetRuntimeObject メソッドを使用する方法の例を次に示します。

C#
// 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();
}

注釈

メソッドが実行時に GetSection 呼び出されると、構成システムは最初に クラスの適切なインスタンスを ConfigurationSection 作成してから、 メソッドから取得したオブジェクトを GetRuntimeObject 返します。

既定では、 GetRuntimeObject 呼び出し元の を表す オブジェクトを ConfigurationSection 返すだけです。

注意 (継承者)

メソッドを GetRuntimeObject() オーバーライドして、実行時にカスタム型を返すことができます。

たとえば、 クラスの ConfigurationSection 設定のランタイム変更を制限するために、変更可能な設定 (ある場合) に制限を適用するカスタム型をオーバーライド GetRuntimeObject() して返すことができます。

ランタイム オブジェクトが内部のみの場合、返されるオブジェクトは、それを定義するアセンブリの外部では使用できません。 から ConfigurationSection 派生し、実行時にアセンブリ内のコードによってのみアクセスできるオブジェクトを作成する方法の 1 つは、実装を返すメソッドを持つ内部ランタイム オブジェクトを ConfigurationSection 作成することです。

適用対象

製品 バージョン
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9