共用方式為


ConfigurationSectionGroup.ForceDeclaration 方法

定義

強制為此 ConfigurationSectionGroup 物件進行宣告。

多載

ForceDeclaration()

強制為此 ConfigurationSectionGroup 物件進行宣告。

ForceDeclaration(Boolean)

強制為此 ConfigurationSectionGroup 物件進行宣告。

ForceDeclaration()

來源:
ConfigurationSectionGroup.cs
來源:
ConfigurationSectionGroup.cs
來源:
ConfigurationSectionGroup.cs

強制為此 ConfigurationSectionGroup 物件進行宣告。

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

範例

下列程式碼範例示範如何使用 ForceDeclaration 方法。

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 可以強制 ConfigurationSectionGroup 物件寫入組態檔,即使它不是必要的,因為它已經宣告在父檔案中。

另請參閱

適用於

ForceDeclaration(Boolean)

來源:
ConfigurationSectionGroup.cs
來源:
ConfigurationSectionGroup.cs
來源:
ConfigurationSectionGroup.cs

強制為此 ConfigurationSectionGroup 物件進行宣告。

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

參數

force
Boolean

如果必須將 ConfigurationSectionGroup 物件寫入檔案中,則為 true,否則為 false

例外狀況

ConfigurationSectionGroup 物件是根區段群組。

-或-

ConfigurationSectionGroup 物件具有位置。

範例

下列程式碼範例示範如何使用 ForceDeclaration 方法。

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會強制將此ConfigurationSectionGroup宣告寫入檔案forcetrue 如果 為 forcefalse,則系統 ConfigurationSectionGroup 需要物件時,可能會忽略此動作。

方法 ForceDeclaration 可以強制 ConfigurationSectionGroup 物件寫入組態檔,即使它不是必要的,因為它已經宣告在父檔案中。 此外,如果不需要群組,它可以從組態檔中移除群組。

您可能想要使用 ForceDeclaration 方法讓組態檔更容易從一部計算機到另一部計算機,而不必擔心群組宣告是否已存在。

另請參閱

適用於