<?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);

App.config自定义节点读取的更多相关文章

  1. 一个web.Config或app.Config自定义段configSections的示例

    一个web.Config或app.Config自定义段configSections的示例 越来越觉得,直接用配置文件app.Config或web.Config配置应用系统的运行参数,比自己做一个xml ...

  2. 如何使用App.config文件,读取字符串?

    如何使用App.config文件,读取字符串? .在项目里添加App.config文件,内容如下: <?xml version="1.0" encoding="ut ...

  3. 读取App.config自定义标签的值

    一:程序截图 二:具体代码 config配置: <?xml version="1.0" encoding="utf-8" ?> <config ...

  4. App.Config自定义配置节点

    配置文件: <?xml version="1.0" encoding="utf-8"?> <configuration> <con ...

  5. Web.config自定义节点configSections

    1.为什么需要自定义节点 为了增加应用程序的可移植性,通常网站需要配置一些自定义的节点,例如:文件上传的路径等,再深入的应用,可以定义工厂方法需要创建的类. 2.configSections使用方法 ...

  6. 一个web.Config或app.Config自定义段configSections的示例--转

    直接用配置文件app.Config或web.Config配置应用系统的运行参数,比自己做一个xml配置文件,简洁方便得多.这两个配置文件不仅有常见的connectionStrings和appSetti ...

  7. C# App.config 自定义 配置节 出现的问题:配置系统未能初始化

    C# 读取app.config配置文件 节点键值,提示 "配置系统未能初始化" 错误的解决方案 新建C#项目,在app.config中添加了appSettings项,运行时出现&q ...

  8. C# App.config 自定义 配置节

    1)App.config <?xml version="1.0" encoding="utf-8" ?><configuration>  ...

  9. C# App.config 自定义 配置节 报错“配置系统未能初始化” 解决方法

    App.config,结果运行的时候出现了 "配置系统未能初始化" 的错误.找了半天才发现是下面的原因造成的: "如果配置文件中包含configSections元素,则c ...

随机推荐

  1. Android P Beta发布!最新版本抢先体验!

    在不久前结束的谷歌I/O开发者大会上,谷歌公布了下一个版本的 Android,也就是 Android P 的 beta 版本.Android P 将 AI 定位为操作系统的核心,并侧重于提供智能且简洁 ...

  2. 如何在ST官网下载STM32固件库

    1.首先要注册一个ST账号,下载的时候需要. 2.找到工具与软件 3.进去之后选"产品列表" 4.在产品列表里选STM32微控制器软件,直接点下图标号2,不要点左边的加号 5.进去 ...

  3. Pc与移动端的测试异同性

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...

  4. appium 出现报错“A new session could not be created. (Original error: Requested a new session but one was in progress)”的解决方式!

    报错点:selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Ori ...

  5. 基于tcp实现远程执行命令

    命令执行服务器: # Author : Kelvin # Date : 2019/1/30 20:10 from socket import * import subprocess ip_conf = ...

  6. java游戏开发杂谈 - 画布和画笔

    在Eclipse里,编写如下两个类: package game2; import java.awt.Color; import java.awt.Graphics; import javax.swin ...

  7. 理解 KMP 算法

    KMP(The Knuth-Morris-Pratt Algorithm)算法用于字符串匹配,从字符串中找出给定的子字符串.但它并不是很好理解和掌握.而理解它概念中的部分匹配表,是理解 KMP 算法的 ...

  8. SpringBoot进阶教程(二十五)整合Redis之@Cacheable、@CachePut、@CacheEvict的应用

    在上一篇文章(<SpringBoot(二十四)整合Redis>)中,已经实现了Spring Boot对Redis的整合,既然已经讲到Cache了,今天就介绍介绍缓存注解.各家互联网产品现在 ...

  9. Asp.NETCore轻松学系列阅读指引目录

    前言 耗时两个多月,坚持写这个入门系列文章,就是想给后来者更好更快的上手体验,这个系列可以说是从入门到进阶,适合没有 .NETCore 编程经验到小白同学,也适合从 .NET Framework 迁移 ...

  10. WPF TextBox 正则验证 大于等于0 小于等于1 的两位小数

    正则:^(0\.\d+|[1-9][0-9]|1)$ TextBox绑定正则验证 <TextBox x:Name="txb"   MaxLength="6" ...