ConfigurationSection.GetRuntimeObject ConfigurationSection.GetRuntimeObject ConfigurationSection.GetRuntimeObject ConfigurationSection.GetRuntimeObject Method

定义

在派生的类中重写时返回自定义对象。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 方法时,配置系统首先创建类的适当实例,然后返回它从方法GetSection获取的对象。When 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.

适用于