ConfigurationSectionGroup.ForceDeclaration ConfigurationSectionGroup.ForceDeclaration ConfigurationSectionGroup.ForceDeclaration ConfigurationSectionGroup.ForceDeclaration Method

Definition

Forces the declaration for this ConfigurationSectionGroup object.

Overloads

ForceDeclaration() ForceDeclaration() ForceDeclaration() ForceDeclaration()

Forces the declaration for this ConfigurationSectionGroup object.

ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean)

Forces the declaration for this ConfigurationSectionGroup object.

ForceDeclaration() ForceDeclaration() ForceDeclaration() ForceDeclaration()

Forces the declaration for this ConfigurationSectionGroup object.

public:
 void ForceDeclaration();
public void ForceDeclaration ();
member this.ForceDeclaration : unit -> unit
Public Sub ForceDeclaration ()

Examples

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

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);
}
Overloads Shared Sub ForceDeclaration( _
ByVal sectionGroup As ConfigurationSectionGroup)

    ' Get the application configuration file.
    Dim config _
    As System.Configuration.Configuration = _
    ConfigurationManager.OpenExeConfiguration( _
    ConfigurationUserLevel.None)

    sectionGroup.ForceDeclaration()

    config.Save(ConfigurationSaveMode.Full)

    Console.WriteLine( _
    "Forced declaration for the group: {0}", _
    sectionGroup.Name)
End Sub 'ForceDeclaration

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

ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean) ForceDeclaration(Boolean)

Forces the declaration for this ConfigurationSectionGroup object.

public:
 void ForceDeclaration(bool require);
public void ForceDeclaration (bool require);
member this.ForceDeclaration : bool -> unit
Public Sub ForceDeclaration (require As Boolean)

Parameters

force
Boolean Boolean Boolean Boolean

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

Exceptions

Examples

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

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

    Console.WriteLine(
        "Forced declaration for the group: {0} is {1}",
        sectionGroup.Name, force.ToString());
}
Overloads Shared Sub ForceDeclaration( _
ByVal sectionGroup _
As ConfigurationSectionGroup, _
ByVal force As Boolean)
    sectionGroup.ForceDeclaration(force)

    Console.WriteLine( _
    "Forced declaration for the group: {0} is {1}", _
    sectionGroup.Name, force.ToString())
End Sub 'ForceDeclaration

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