如何更改自定义ConfigurationSection的显示名称?

时间:2015-01-15 18:50:53

标签: .net

我正在构建一个自定义ConfigurationSection,以便在演示应用程序中使用。我给继承自ConfigurationSection的类的名称是应用程序在配置文件中查找的部分名称。如何更改此行为?

这是继承自ConfigurationSection的类的骨架:

public class LongNameBecauseItsTheResultOfFollowingAnOtherwiseGoodConvention: ConfigurationSection
{
   ...    
}

app.config文件中,它希望看到以下部分:

<LongNameBecauseItsTheResultOfFollowingAnOtherwiseGoodConvention>
  ...
</LongNameBecauseItsTheResultOfFollowingAnOtherwiseGoodConvention>

如何在app.config中使用较短的部分名称,但在源代码中遵循我们的约定?

1 个答案:

答案 0 :(得分:1)

ConfigurationSection文件的<configSections>元素中定义app.config时,您可以指定其他名称。

<configuration>
  <configSections>
    <section name="ABC123" type="namespaceName.className, assemblyName"/>
  </configSections>
</configuration>