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,面向服务架构,粗粒度.开放式.松耦合的服务结构,将应用程序 ...
随机推荐
- mysql 查询 7天内的数据
SELECT ID,SERVICE FROM new_schedules_spider_full WHERE SERVICE = 'WSA2' and date_sub(curdate(), inte ...
- 三、Linux 系统目录结构
Linux 系统目录结构 登录系统后,在当前命令窗口下输入命令: ls / 你会看到如下图所示: 树状目录结构: 以下是对这些目录的解释: /bin:bin是Binary的缩写, 这个目录存放着最 ...
- ZendFramework-2.4 源代码 - ViewManager类图
- Python3中的列表用法,看这一篇就够了
类似C语言中的列表用法 ---------------------------------------------------------------------------------------- ...
- 100个经典C语言程序(益智类)
100个经典C语言程序(益智类) [1.绘制余弦曲线] 在屏幕上用“*”显示0~360度的余弦函数cos(x)曲线 [问题分析与算法设计] 利用cos(x)的左右对称性,将屏幕的行方向定义为x,列方向 ...
- Ntdsutil.exe
Ntdsutil.exe 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! Ntdsutil.exe 是一个为 Active Directory 提供管理设施的命令行工具 ...
- leetcode 【 Unique Paths 】python 实现
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- MFC深入浅出读书笔记第二部分2
第七章 MFC骨干程序 所谓骨干程序就是指有AppWizard生成的MFC程序.如下图的层次关系是程序中常用的几个类,一定要熟记于心. 1 Document/View应用程序 CDocument存放 ...
- CentOS7安装Code::Blocks
在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum install gccyum instal ...
- [oldboy-django][1初始django]模态对话框 + 动态加载gif (多对多数据库表)
ajax+对话框(多对多) - 遮罩层,动态加载gif层,对话框层, a.一点击添加,绑定事件: - 出现遮罩层和动态gif层 - ajax向后台发送请求获取所有班级数据 - success,隐藏动态 ...