c# winform 下的装载appconfig的section配置节的问题
一直喜欢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分,可以追加~~