ConfigurationSectionGroup.ForceDeclaration 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
强制声明此 ConfigurationSectionGroup 对象。
重载
ForceDeclaration() |
强制声明此 ConfigurationSectionGroup 对象。 |
ForceDeclaration(Boolean) |
强制声明此 ConfigurationSectionGroup 对象。 |
ForceDeclaration()
- Source:
- ConfigurationSectionGroup.cs
- Source:
- ConfigurationSectionGroup.cs
- Source:
- 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)
- Source:
- ConfigurationSectionGroup.cs
- Source:
- ConfigurationSectionGroup.cs
- Source:
- 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
。
例外
示例
下面的代码示例说明如何使用 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
注解
如果 force
为 true
,则ForceDeclaration方法强制将此ConfigurationSectionGroup声明写入文件。 如果 force
为 false
,则系统需要 对象时 ConfigurationSectionGroup ,可能会忽略此操作。
方法 ForceDeclaration 可以强制 ConfigurationSectionGroup 将对象写入配置文件,即使不需要它,因为它已在父文件中声明。 此外,如果不需要组,它可以从配置文件中删除组。
你可能希望使用 ForceDeclaration 方法使配置文件在一台计算机上更易于移植到另一台计算机,而无需担心组声明是否已存在。