技术开发 频道

揭开.NET 2.0配置隐藏的秘密

        通过传递Configuration对象,一个可保存的配置节实例能在XML文件中检索一个指定名字的配置节。这把我带到另外一个重要的配置节秘诀。配置节元素的名字不一定必须的固定不变,也不一定只有一个配置节的实例。在一个.config文件按中每个配置节可以定义和设置多次,只要给每个实例不同的名字:

<configuration>
  
<configSections>
    
<section name="example1" type="Examples.Configuration.ExampleSection,
                                      Examples.Configuration" />
    <section name="example2" type="Examples.Configuration.ExampleSection,
                                      Examples.Configuration" />
    <section name="example3" type="Examples.Configuration.ExampleSection,
                                      Examples.Configuration" />
  </configSections>
  
  
<example1 />
  
<example2 />
  
<example3 />
</configuration>
0
相关文章