Configuration Section Designer注意的地方

Configuration Section Designer是什么?
A Visual Studio add-in that allows you to graphically design .NET Configuration Sections and automatically generates all the required code and a schema definition (XSD) for them.
  官方主页:http://csd.codeplex.com/
      简单的说,就是一个VS插件,可以通过设计XSD架构生成强类型的配置,对于复杂的配置,当然你可以用手工写,继承自System.Configuration.ConfigurationSection,写相应的属性、集合,。。。。。如果配置较复杂或者属性较多,这就成了一项体力活,这个时候工具就发挥了作用了,Configuration Section Designer就是这么一个工具,集成到VS IDE,非常方便。


现在这个版本对中文的VS支持得不好,但是基本功能可以用,安装完后没有生成VS的文件模板,如果要使用,可以在下载的源码中可以找到下面几个文件
  • ConfigurationSection.csd: the designer itself.
  • ConfigurationSectionCode.tt: a text template code generator that generates the C# code for the configuration section.
  • ConfigurationSectionSample.tt: generates a sample configuration file.
  • ConfigurationSectionSchema.tt: generates the XSD schema representing the configuration section.
把这几个文件复制或添加到项目里面,然后对
ConfigurationSection.csd进行设计,设计完成后会自动成功配置的代码。
值得注意的是,生成的示例xxxsample.config文件中,
    <configSections>
        
<section name="testConfiguration" type="TestConfig.Config.TestConfiguration"/>
    
</configSections>
type="TestConfig.Config.TestConfiguration" 后面要加程序集名,否则加载会出错,实际上就是在反射的时候要根据完全限定名来加载程序集才能正确的加载
type="TestConfig.Config.TestConfiguration,TestConfig"

具体的使用可以参考 蝈 蝈的这篇博文




posted @ 2009-08-29 16:47  代码乱了  阅读(860)  评论(0编辑  收藏  举报