ConfigurationSectionGroup.ForceDeclaration Method

Definition

Forces the declaration for this ConfigurationSectionGroup object.

Overloads

ForceDeclaration()

Forces the declaration for this ConfigurationSectionGroup object.

ForceDeclaration(Boolean)

Forces the declaration for this ConfigurationSectionGroup object.

ForceDeclaration()

Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs

Forces the declaration for this ConfigurationSectionGroup object.

C#
public void ForceDeclaration();

Examples

The following code example shows how to use the ForceDeclaration method.

C#
static void ForceDeclaration(
    ConfigurationSectionGroup sectionGroup)
{

    // Get the application configuration file.
    System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None);

    sectionGroup.ForceDeclaration();

    config.Save(ConfigurationSaveMode.Full);

    Console.WriteLine(
        "Forced declaration for the group: {0}",
        sectionGroup.Name);
}

Remarks

The ForceDeclaration method can force a ConfigurationSectionGroup object to be written to a configuration file, even if it is not required because it is already declared in a parent file.

See also

Applies to

.NET 9 (package-provided) and other versions
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

ForceDeclaration(Boolean)

Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs
Source:
ConfigurationSectionGroup.cs

Forces the declaration for this ConfigurationSectionGroup object.

C#
public void ForceDeclaration(bool force);

Parameters

force
Boolean

true if the ConfigurationSectionGroup object must be written to the file; otherwise, false.

Exceptions

The ConfigurationSectionGroup object is the root section group.

-or-

The ConfigurationSectionGroup object has a location.

Examples

The following code example shows how to use the ForceDeclaration method.

C#
static void ForceDeclaration(
    ConfigurationSectionGroup sectionGroup,
    bool force)
{
    sectionGroup.ForceDeclaration(force);

    Console.WriteLine(
        "Forced declaration for the group: {0} is {1}",
        sectionGroup.Name, force.ToString());
}

Remarks

The ForceDeclaration method forces this ConfigurationSectionGroup declaration to be written to the file if force is true. If force is false, this action might be ignored if the ConfigurationSectionGroup object is required by the system.

The ForceDeclaration method can force a ConfigurationSectionGroup object to be written to a configuration file, even if it is not required because it is already declared in a parent file. Also, it can remove a group from a configuration file if the group is not required.

You might want to use the ForceDeclaration method to make a configuration file more portable from one computer to another, without worrying about whether the group declaration already exists.

See also

Applies to

.NET 9 (package-provided) and other versions
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