ConfigurationSection.GetRuntimeObject Method

Definition

Returns a custom object when overridden in a derived class.

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

Returns

The object representing the section.

Examples

The following example shows how to use the GetRuntimeObject method.

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

Remarks

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.

By default, GetRuntimeObject simply returns the object that represents the ConfigurationSection from which it is called.

Notes to Inheritors

You can override the GetRuntimeObject() method to return a custom type at run time.

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

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided)
.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 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9