一直喜欢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 用户信息管理(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分,可以追加~~
右键点击项目看这个类在那个DLL里。 第一个问题解决不掉,第二个自然也就是null了
可以说的具体点吗??
<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;
XXX应该是程序集的全称 .