【问题标题】:Is it possible to write configuration section handler by code?是否可以通过代码编写配置节处理程序?
【发布时间】:2012-08-06 14:53:18
【问题描述】:

我正在使用 app.config 文件编写新应用程序。

这是我的 app.config:

<configuration>
  <configSections>
    <sectionGroup name="FTPServers">
    <section name="section1" type="System.Configuration.SingleTagSectionHandler" />
      <section name="section2" type="System.Configuration.SingleTagSectionHandler" />
</sectionGroup>
    <sectionGroup name="Application">
      <section name="Section3" type="System.Configuration.SingleTagSectionHandler" />
      <section name="Section4" type="System.Configuration.SingleTagSectionHandler" />
      <section name="Section5" type="System.Configuration.DictionarySectionHandler" />
    </sectionGroup>
    </configSections>

是否可以通过代码尽快在节组中添加节?

我想在我的程序中创建一个表单来修改这个配置,创建节组和在配置节之后...

谢谢

【问题讨论】:

  • 您不能直接从代码修改应用程序设置,只能修改用户设置。

标签: c# app-config


【解决方案1】:

您不能直接从代码修改应用程序设置,只能修改用户设置。也就是说,不是使用可以从中读取设置的常用 API。也许你可以使用默认的文本 IO 来编辑文件,但不推荐。

这是因为启动程序的所有用户都使用 app.config。一位用户在运行程序时更改 app.config 可能会给当前正在运行该程序的其他用户带来令人惊讶的结果。

您可以使用 user.config 来编辑用户设置或使用不同的配置机制。 app.config 主要是静态配置,只需要管理员修改即可。

【讨论】:

  • 好的,谢谢支持。我将继续使用这个 app.config,但我只会编写更改部分设置的方法...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多