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,面向服务架构,粗粒度.开放式.松耦合的服务结构,将应用程序 ...
随机推荐
- matplotlib(一)——matplotlib横轴坐标密集字符覆盖
一.问题描述 具体问题是: 用python库matplotlib进行数据的图表展示: 图表展示图形横坐标有将近100个自定义值需要显示: 保存矢量图(svg),保存后发现横坐标过于密集,坐标值之间有覆 ...
- 17.VUE学习之- v-for指令的使用方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python练手习题
不断记录python常见习题,不断寻求更多更好的解决办法.持续更新中..... 练习: 1. list两两元素交换位置,如[1,2,3,4,5,6] 执行后为 -> [2,1,4,3,6,5] ...
- HDU:2846-Repository
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others) ...
- SHIWEITI
//Wannafly挑战赛19(牛客网) //A 队列Q #include <iostream> #include <cstdio> #include <cstring& ...
- Storm: 遇到问题总结
1.没有ack : kafkaspout id 重复导致每次读最新没有数据. 2.由于storm提供的读取kafka的enternal工具存在bug,导致重复读取数据,致使数据不准确.storm bu ...
- 裸奔着造房子——对政府禁止采购Win8系统的一些看法
前段时间有消息称政府招标的项目将禁止使用Win8系统,原因是Win8系统的安全架构将有利于暴露敏感信息给微软,而微软的老子是美利坚,老子想要知道什么,儿子当然不敢不从.因此Win8也被打入冷宫,微软多 ...
- 关于mybatis 一级缓存引发的问题
场景: 由于在一个方法中存在多个不同业务操作 private void insertOrUpdateField(CompanyReport entity) { //计算并数据 calcReportDa ...
- Apache Compress-使用
Apache Compress 是什么? Apache 提供的文件压缩工具. 运行环境 jdk 1.7 commons-compress 1.15 测试代码 package com.m.basic; ...
- 【Next Permutation】cpp
题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...