configurationmanager.getsection usage example.
1.app.config(note that attribute case sensitive!)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--configsections must be placed above most! or there may be a "Configuration System Failed to Initialize" error!-->
<configSections>
<!--section type equals format- "type,assemblyname"-->
<section name="CustomConfig" type="SrvListQueryConsole.CustomConfig, SrvListQueryConsole"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<!--config "Value" case sensitive-->
<CustomConfig>
<Name Value="asdf"/>
</CustomConfig>
</configuration>
2.class (should impliment interface IConfigurationSectionHandler)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Xml; namespace SrvListQueryConsole
{
class Program
{ static void Main(string[] args)
{
var m = ConfigurationManager.GetSection("CustomConfig") as CustomConfig;
Console.WriteLine(m.Name); if (args.Length != 2) return;
//System.Windows.Forms.Form fm = new ServerListQueryFormDll.SrvListQueryFrm(args[0],args[1]);
//fm.ShowDialog();
Console.Read();
}
} //mapping!
public class CustomConfig : IConfigurationSectionHandler
{
public string Name { get; private set; }
public object Create(object parent, object configContext, XmlNode section)
{
CustomConfig config = new CustomConfig();
var name = section.SelectSingleNode("Name");
if (name != null && name.Attributes != null)
{
var attribute = name.Attributes["Value"];
if (attribute != null)
config.Name = attribute.Value;
}
return config;
}
}
}
configurationmanager.getsection usage example.的更多相关文章
- configurationmanager.getsection usage
public static void CreateAppSettings() { // Get the application configuration file. System.Configura ...
- ConfigurationManager.GetSection()方法的使用
GetSection方法读取的是configSections节点,这个节点在web.config配置文件中,它比较特殊,必须放置于首节点,也就是说,在它之前不能有其它类型的节点.configSecti ...
- ASP.NET 系列:单元测试之ConfigurationManager
通过ConfigurationManager使用.NET配置文件时,可以通过添加配置文件进行单元测试,虽然可以通过测试但达不到解耦的目的.使用IConfigurationManager和Configu ...
- System.ConfigurationManager类用于对配置文件的读取
http://blog.csdn.net/ligenyingsr/article/details/54095986 System.ConfigurationManager类用于对配置文件的读取.其具有 ...
- .NetCore技术研究-ConfigurationManager在单元测试下的坑
最近在将原有代码迁移.NET Core, 代码的迁移基本很快,当然也遇到了不少坑,重构了不少,后续逐步总结分享给大家.今天总结分享一下ConfigurationManager遇到的一个问题. 先说一下 ...
- MongoDb 配置笔记
安装: 官网:https://www.mongodb.org/ 按官方教程: http://docs.mongodb.org/master/tutorial/install-mongodb-on-re ...
- Akka.net路径里的user
因为经常买双色球,嫌每次对彩票号麻烦,于是休息的时候做了个双色球兑奖的小程序,做完了发现业务还挺复杂的,于是改DDD重做设计,拆分服务,各种折腾...,不过这和本随笔没多大关系,等差不多了再总结一下, ...
- 一步步开发自己的博客 .NET版(11、Web.config文件的读取和修改)
Web.config的读取 对于Web.config的读取大家都很属性了.平时我们用得比较多的就是appSettings节点下配置.如: 我们对应的代码是: = ConfigurationManage ...
- WCF基础
初入职场,开始接触C#,开始接触WCF,那么从头开始学习吧,边学边补充. SOA Service-Oriented Architecture,面向服务架构,粗粒度.开放式.松耦合的服务结构,将应用程序 ...
随机推荐
- (SSO)单点登录原理和总结
一:什么是单点登录(single Sign-On) SSO 是一种统一认证和授权机制,指访问统一服务器不用应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后, 再访问其他应用中 ...
- arduino 语音音箱 :语音控制、MP3播放、报时、回复温湿度情况
arduino 语音音箱 :语音控制.MP3播放.报时.回复温湿度情况 效果图 线路图 包装后的效果 功能 需要材料 arduino板 MP3播放模块及喇叭 时钟模块 温湿度模块 语音识别模块 面包板 ...
- 解决国内网络Python2.X 3.X PIP安装模块连接超时问题
pip国内的一些镜像 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/si ...
- HDU 1423 Greatest Common Increasing Subsequence(LCIS)
Greatest Common Increasing Subsequenc Problem Description This is a problem from ZOJ 2432.To make it ...
- 洛谷 P2279 [HNOI2003]消防局的设立
题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了一个巨大的树状 ...
- JZOJ 5776. 【NOIP2008模拟】小x游世界树
5776. [NOIP2008模拟]小x游世界树 (File IO): input:yggdrasil.in output:yggdrasil.out Time Limits: 1500 ms Me ...
- wusir 面试题答案在老男孩的视频里
注意:你问答案在哪里?答案在视频里了,就是不给你写. 第一部分 Python基础篇(80题) 为什么学习Python? 通过什么途径学习的Python? Python和Java.PHP.C.C#.C+ ...
- linux下的source命令
Linux Source命令及脚本的执行方式解析 当我修改了/etc/profile文件,我想让它立刻生效,而不用重新登录:这时就想到用source命令,如:source /etc/profile ...
- MySQL查询数据库中表名或字段名
查询数据库中所有表名 select table_name from information_schema.tables where table_schema='csdb' and table_type ...
- iview框架 两侧弹框 出现第二层弹框 一闪而过的问题
分析原因:寡人怀疑可能是,两层弹出框 采用的是一个开关值,发生了覆盖 解决方式 是在第二层弹框外套层计时器 源代码如下: 修改后为: