System.Configuration.ConfigurationSection.GetRuntimeObject 方法

方法描述

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

语法定义(C# System.Configuration.ConfigurationSection.GetRuntimeObject 方法 的用法)

protected internal virtual Object GetRuntimeObject()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.Object 表示节的对象。

提示和注释

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

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

对实现者的说明

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

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

如果运行时对象是仅限内部使用的,则返回的对象无法在定义该对象的程序集之外使用。 要创建从 ConfigurationSection 派生并且只能在运行时通过程序集中的代码进行访问的对象,一种方法就是创建内部运行时对象,其具有可返回 ConfigurationSection 实现的方法。

System.Configuration.ConfigurationSection.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();
        }

异常

异常 异常描述

命名空间

namespace: System.Configuration

程序集: System.Configuration(在 System.Configuration.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。