一直喜欢theBeerHouse的三层架构,这次碰到一个weinform下的编程项目,自己想继续沿用thebeerhouse的方法:在配置文件中写section,关于系统各个模块,比如
系统包含:
  1 用户信息管理(user)
  2 订单信息管理(order)
  3 客户信息管理(customer)
在配置中自定义配置节<section name="MyProject" Type="Com.MyProject.MyConfigSection,XXX">  (问题1,在web中,都是用 __code来代替XXX,但是在winform中,我不知道该用什么表示,想请教一下高手?)
                 <MyProject defaultConnectionStringName="MyString">
                   <user pageSize="10">
                   <order>
                   <customer>
                  </MyProject>
然后在系统代码里构建ConfigurationSection的子类实现程序的基本配置:
        namespace Com.MyProject
       {
           public class MyConfigSection:ConfigurationSection
          {
              [ConfigurationProperty("defaultConnectionStringName",DefaultValue="MyString")]
              public string DefaultConnectionStringName
              {
                get{return (string)base["defaultConnectionStringName"];}
              }
              ***************************
              **** 一些配置元素的章节******
              ***************************
          }
        }
问题出现在构建全局环境的Globals类里:
       namespace Com.MyProject{
       public static class Globals
       {
          public static readonly MyConfigSection Settings = (MyConfigSection)ConfigurationManager.GetSection("MyProject"); 
          //问题2:这里的 (MyConfigSection)ConfigurationManager.GetSection("MyProject")每次加载的都是null,导致系统无法加载配置
       }
      }
上述两2个问题:如上,请教高手,100分,可以追加~~

解决方案 »

  1.   

    http://blog.csdn.net/BlueTzar/archive/2007/03/19/1534218.aspx
      

  2.   

    谢谢wuyq11的回复,我描述不是这个问题。我想要的是section和程序里的类的对应关系的建立
      

  3.   

    XXX就是DLL
    右键点击项目看这个类在那个DLL里。 第一个问题解决不掉,第二个自然也就是null了
      

  4.   

    maddemon的意思是,要把配置类编译成dll?然后表示在<section>的type中?
    可以说的具体点吗??
      

  5.   

    200分给我吧 我给你说~   我不知道你的那个描述节点的类 写的对不对下面的代码是我写的一个叫CustomDataSection的节点描述的类  用的时候如下Config:
      <configSections>
        <section name="MyCustomDataSection" type="CustomDataSection.CustomDataSection,CustomDataSection" />
      </configSections>
    type  第一个是表示"命名空间.类名,Dll的名字"
    具体调用:
     Configuration config = null;
                    ExeConfigurationFileMap FileMap = new ExeConfigurationFileMap();
                    FileMap.ExeConfigFilename = myOpenFilgDlg.FileName;
                    config = ConfigurationManager.OpenMappedExeConfiguration(FileMap, ConfigurationUserLevel.None);
                    CustomDataSection.CustomDataSection CustomsData = config.GetSection("MyCustomDataSection") as CustomDataSection.CustomDataSection;
      

  6.   

    那个XXX 你应该填写你dll的名字
      

  7.   

    如果有类全路径 如果要获取类的实例或则TYPE 那还需要一个程序集名称
    XXX应该是程序集的全称 .
      

  8.   

    你看下 Com.MyProject.MyConfigSection 在项目的程序集名称 添写上就好了
      

  9.   

    解决了,谢谢各位,特别是maddemon大哥