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,面向服务架构,粗粒度.开放式.松耦合的服务结构,将应用程序 ...
随机推荐
- linux替换yum源及配置本地源
linux系统安装后自带的bash源由于在国外,安装软件包的时候会非常慢,最好替换一下yum源. 关于yum源的简单介绍 yum的主要功能是更方便地添加,删除和更新rpmba ...
- 在windows上搭建镜像yum站的方法
在windows上搭建镜像yum站的方法(附bat脚本) 分类: 运维基本功,其他 方法一:支持rsync的网站 对于常用的centos.Ubuntu.等使用官方yum源在 http://mi ...
- vue.js 图表chart.js使用
在使用这个chart.js之前,自己写过一个饼图,总之碰到的问题不少,所以能用现成的插件就用,能节省不少时间 这里不打算介绍chart.js里面详细的参数意义和各个参数的用法,只作为首次使用chart ...
- Foxmail登录不了网易企业邮箱解决办法
关于Foxmail登录不了网易企业邮箱问题 解决办法是:在设置账号的时候手动设置pop服务器和smtp服务器. 新建账号的图: 点击“手动设置”出现如下界面: 设置完成后问题解决.下面的两个是正确的, ...
- g++编译器的使用(转载)
关于g++ g++ 是GNU组织开发出的编译器软件集合(GCC)下的一个C++编译器.它是Unix 和 Linux 系统下标配的 基于命令行的 C++编译器.如果你的系统是Windows,可以按照 ...
- Roads in the North POJ - 2631
Roads in the North POJ - 2631 Building and maintaining roads among communities in the far North is a ...
- JQ剪辑图片插件,适用于移动端和PC端
主要用到以下JS文件: <script src="js/photo/iscroll-zoom.js"></script> <script src=&q ...
- Hive UDTF开发指南
在这篇文章中,我们将深入了解用户定义表函数(UDTF),该函数的实现是通过继承org.apache.Hadoop.hive.ql.udf.generic.GenericUDTF这个抽象通用类,UDTF ...
- 菜鸟学Linux - Linux文件属性
在Linux中,文件的属性是一个很重要的概念,用户或者用户组对一个文件所拥有的权限,都可以从文件的属性得知. 我们可以通过ls -al命令,列出某个文件夹下面的所有文件(包括以.开头的隐藏文件).下面 ...
- 16,Python网络爬虫之Scrapy框架(CrawlSpider)
今日概要 CrawlSpider简介 CrawlSpider使用 基于CrawlSpider爬虫文件的创建 链接提取器 规则解析器 引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话, ...