public class OtherConfigInfo : ConfigurationSection { ////// 获取配置信息 /// ///public static OtherConfigInfo GetConfig() { return GetConfig("otherconfig"); } /// /// 获取配置信息 /// /// xml节点名称 ///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);