App.config自定义节点读取

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--<otherconfig configSource="XmlConfig\other.config" />-->
<otherconfig a="" b="" c=""/>
</configuration>
public class OtherConfigInfo : ConfigurationSection
{
/// <summary>
/// 获取配置信息
/// </summary>
/// <returns></returns>
public static OtherConfigInfo GetConfig()
{
return GetConfig("otherconfig");
}
/// <summary>
/// 获取配置信息
/// </summary>
/// <param name="sectionName">xml节点名称</param>
/// <returns></returns>
public static OtherConfigInfo GetConfig(string sectionName)
{
OtherConfigInfo section = (OtherConfigInfo)ConfigurationManager.GetSection(sectionName);
if (section == null)
throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
return section;
} [ConfigurationProperty("a", IsRequired = false)]
public string a
{
get
{
return (string)base["a"];
}
set
{
base["a"] = value;
}
} [ConfigurationProperty("b", IsRequired = false)]
public string b
{
get
{
return (string)base["b"];
}
set
{
base["b"] = value;
}
} [ConfigurationProperty("c", IsRequired = false)]
public string c
{
get
{
return (string)base["c"];
}
set
{
base["c"] = value;
}
}
}

  

 //调用方法
OtherConfigInfo configInfo = OtherConfigInfo.GetConfig();
Console.WriteLine(configInfo.a);
上一篇:mysqldump导入导出mysql数据库


下一篇:SQL学习之MYSQL的常用命令和增删改查语句和数据类型