如何使用app.config中的“用户设置”和“自定义配置”部分?
<mySection id="myId">
<item1 data="info">
<item2 data="more info">
</mySection>
并将它们链接到一个类型。
app.config
键值对在哪里?
appSettings
如何?举个例子
<add key="File_Count" value="2" />
。CS
什么类可以访问用户设置?
System.Configuration.ConfigurationManager
项目必须参考什么?
System.Configuration
哪种方法提供基本设置?上面的例子
AppSettings["File_Count"]
鉴于以下自定义部分
<mySection id="myId">
<item1 data="info">
<item2 data="more info">
</mySection>
对于“ myAssembly”中名为“ Sample.myType”的类类型,需要在应用文件中声明此内容吗?
<configSections>
<section name="mySection" type="Sample.myType, myAssembly" />
</configSections>
xml元素映射到c#属性的映射是什么?
mySection ConfigurationSection
item Type ConfigurationElement
xml属性到c#属性的映射是什么?
id ConfigurationProperty
data ConfigurationProperty
item1 ConfigurationProperty
item2 ConfigurationProperty
如何声明“ myType”类型的类?
public class myType : ConfigurationSection {
如何声明一个简单的属性“ id”?
//Inside myType as
[ConfigurationProperty("id", IsRequired = false)]
public string Id {
get { return (string)this["id"]; }
set { this["id"]=value;}
}
如何声明item元素的类型?
//Inside myType as a sub class
public class myTypeElement : ConfigurationElement {
[ConfigurationProperty("data", IsRequired = false)]
public string Data {
get { return (string)this["data"]; }
set { this["data"]=value;}
}
}
如何声明项目元素?
[ConfigurationProperty("item1)]
public myTypeElement Item1{
get { return (myTypeElement)this["item1"] }
set { this["item1"]=value;}
}
如何从组名“ mySection”访问这些文件?
Sample.myType t = (Sample.myType)System.Configuration.ConfigurationManager.GetSection("mySection");
string s = t.item1.data;
这在MSDN和其他地方在哪里?
如何:使用ConfigurationSection创建自定义配置节
msdn.microsoft.com/zh-CN/library/system.configuration.configurationmanager.appsettings.aspx
blog.danskingdom.com/在您的c-app-config /中添加和访问自定义部分
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句