ConfigurationSection.GetRuntimeObject 方法

定義

在衍生類別中覆寫時,傳回自訂物件。Returns a custom object when overridden in a derived class.

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

傳回

表示區段的物件。The object representing the section.

範例

下列範例會示範如何使用 GetRuntimeObject 方法。The following example shows how to use the GetRuntimeObject method.

// 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

備註

在執行時間呼叫ConfigurationSection GetRuntimeObject方法時,設定系統會先建立適當的類別實例,然後再傳回它從方法取得的物件。 GetSectionWhen the GetSection method is called at run time, the configuration system first creates an appropriate instance of the ConfigurationSection class, and then returns the object it obtains from the GetRuntimeObject method.

根據預設, GetRuntimeObject只會傳回代表從中呼叫它ConfigurationSection之的物件。By default, GetRuntimeObject simply returns the object that represents the ConfigurationSection from which it is called.

給繼承者的注意事項

您可以覆寫GetRuntimeObject()方法,以在執行時間傳回自訂類型。You can override the GetRuntimeObject() method to return a custom type at run time.

例如,若要限制ConfigurationSection類別中設定的執行時間修改,您可以覆寫GetRuntimeObject()並傳回自訂類型,強制執行可修改哪些設定的限制(如果有的話)。For example, to restrict runtime modification of the settings in the ConfigurationSection class, you can override GetRuntimeObject() and return a custom type that enforces restrictions on which settings can be modified, if any.

如果執行時間物件僅供內部使用,則傳回的物件不能用在定義它的元件外部。If the runtime object is internal only, the returned object cannot be used outside the assembly that defines it. 建立衍生自ConfigurationSection的物件,並且只能在執行時間由元件中的程式碼存取的一種方式,就是建立具有傳回您ConfigurationSection的實作為方法的內部執行時間物件。One way to create an object that derives from ConfigurationSection and can only be accessed by code in your assembly at run time is to create an internal runtime object that has a method that returns your ConfigurationSection implementation.

適用於