标签: custom-sections

如何在app.config中获取自定义部分的intellisense?

我的app.config文件中有一个与我们的Io​​C容器类相关的自定义部分.在编辑本节的配置文件时,如何获取intellisense,以及摆脱编译器消息,通知我缺少的模式.

我在这里找到了这个问题:app.config configSections自定义设置无法找到架构信息,但我不明白它是否适用于我的问题,以及如果有的话如何使用答案.

我还找到了这个页面如何在Visual Studio .NET中获取Web.config和App.config的Intellisense,但它说在运行应用程序之前删除了xmlns属性.这真的是唯一/最好的方式吗?

以下是一个简单文件的示例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="ServiceContainers"
        type="LVK.IoC.RegistrationsSectionHandler, LVK"/>
  </configSections>
  <ServiceContainers>
    <Registration type="DatabaseConnection" class="DatabaseConnection">
      <Parameter name="connectionString" type="System.String"
          value="TYPE=MSSQL2000;SERVER=localhost;DATABASE=db"/>
    </Registration>
  </ServiceContainers>
</configuration>
Run Code Online (Sandbox Code Playgroud)

基本上我希望能够<R<ServiceContainers>节点内输入,并在intellisense下拉列表中向我建议注册,以及它的相应属性.

.net c# configuration app-config custom-sections

31
推荐指数
1
解决办法
1万
查看次数

app.config:如何使一个名为appSettings的嵌套customSection成为ConfigurationManager.AppSettings

我想要的app.config是这样的:

<configSections>
        <sectionGroup name="QA_Environment">
            <section name="databases" type="System.Configuration.NameValueSectionHandler"/>
            <section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
        <sectionGroup name="Production_Environment">
            <section name="databases" type="System.Configuration.NameValueSectionHandler"/>
            <section name="storageSystems" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
    </configSections>
Run Code Online (Sandbox Code Playgroud)

...然后我就得到了正确的组和部分.但是我会对任何有效或更好的建议感到满意.我现在已经降低了我的愿望:

    <configSections>
    <sectionGroup name="QA_Environment">
        <section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
    <sectionGroup name="Production_Environment">
        <section name="appSettings" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
</configSections>
Run Code Online (Sandbox Code Playgroud)

我想这很好......我想知道的主要问题是,如果我可以将这些部分中的一个替换为根级别的appSettings ...而不必迭代它们并以编程方式添加或创建配置并保存它.我只希望用户能够选择一个环境,select事件将改变appSettings ...

我面临的一个限制是我引用的数据层需要保持原样....所以我基本上需要让我的app.config可以像目前这些其他项目一样访问......那就是ConfigurationManager.AppSettings [afdasdf]

如果需要澄清,请告诉我...谢谢

c# configurationmanager app-config appsettings custom-sections

6
推荐指数
1
解决办法
9099
查看次数