ConfigurationSection.GetRuntimeObject 方法

定义

在派生的类中重写时返回自定义对象。

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

返回

表示节的对象。

示例

下面的示例显示如何使用 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();
}

注解

GetSection在运行时调用 方法时,配置系统首先创建 类的ConfigurationSection相应实例,然后返回它从 GetRuntimeObject 方法获取的对象。

默认情况下, GetRuntimeObject 只需返回表示 ConfigurationSection 从中调用它的 的 的对象。

继承者说明

可以重写 方法, GetRuntimeObject() 以在运行时返回自定义类型。

例如,若要限制类中 ConfigurationSection 设置的运行时修改,可以重写 GetRuntimeObject() 并返回一个自定义类型,该类型强制实施可修改设置的限制(如果有)。

如果运行时对象仅在内部,则返回的对象不能在定义它的程序集外部使用。 创建派生自 ConfigurationSection 且只能在运行时由程序集中的代码访问的对象的方法之一是创建具有返回 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