第13章 .NET应用程序配置
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Xml; namespace CustomConfig
{
public class MailServerConfigHandler:IConfigurationSectionHandler
{
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
MailServerConfig config = new MailServerConfig();
config.Provider = section.Attributes["provider"] == null ? "" : section.Attributes["provider"].Value;
foreach (XmlNode child in section.ChildNodes)
{
MailServer server = new MailServer();
server.Client = child.Attributes["client"] == null ? "" : child.Attributes["client"].Value;
foreach (XmlNode grandChild in child.ChildNodes)
{
server.ServerNode.Add(grandChild.Name, grandChild.InnerText);
}
config.Add(server);
}
return config;
}
} public class MailServer
{
private Hashtable serverNode;
public MailServer()
{
serverNode = new Hashtable();
} public Hashtable ServerNode
{
get { return serverNode; }
} public string Client { get; set; } public string Address
{
get { return serverNode["address"] as string; }
} public string UserName
{
get { return serverNode["username"] as string; }
} public string Password
{
get { return serverNode["password"] as string; }
}
} public class MailServerConfig : List<MailServer>
{
public string Provider { get; set; }
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="mailServerGroup" type="CustomConfig.MailServerConfigHandler,CustomConfig"/>
</configSections> <mailServerGroup provider="www.edong.com">
<mailServer client="forum.tracefact.net">
<address>addr1</address>
<userName>user1</userName>
<password>pwd1</password>
</mailServer> <mailServer client="blog.tracefact.com">
<address>addr2</address>
<userName>user2</userName>
<password>pwd2</password>
</mailServer>
</mailServerGroup>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CustomConfig;
using System.Configuration; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
example();
} private static void example()
{
MailServerConfig serverGroup = (MailServerConfig)ConfigurationManager.GetSection("mailServerGroup");
Console.WriteLine("provider:\t"+serverGroup.Provider);
foreach (MailServer config in serverGroup)
{
Console.WriteLine("-------------------------------");
Console.WriteLine("client:\t"+config.Client);
Console.WriteLine("address:\t"+config.Address);
Console.WriteLine("userName:\t"+config.UserName);
Console.WriteLine("password:\t"+config.Password);
}
Console.ReadKey();
}
}
}
第13章 .NET应用程序配置的更多相关文章
- 鸟哥的Linux私房菜-第10/11/12/13章(vim程序编辑器、学习bash、正则表达式与文件格式化处理、学习Shell Scripts)
第10章 vim程序编辑器 可以将vim看做vi的进阶版本,vim可以用颜色或底线等方式来显示出一些特殊的信息. 为何要学习vim?因为: a. 所有的 Unix Like 系统都会内建 vi 文书编 ...
- sql server 2000安装程序配置服务器失败
第一种方法 今天安装SQL Server 2000遇到了个很BT的问题,提示出下: 安装程序配置服务器失败.参考服务器错误日志和C:\Windows\sqlstp.log了解更多信息. 以前进安装目录 ...
- ASM:《X86汇编语言-从实模式到保护模式》第13章:保护模式下内核的加载,程序的动态加载和执行
★PART1:32位保护模式下内核简易模型 1. 内核的结构,功能和加载 每个内核的主引导程序都会有所不同,因为内核都会有不同的结构.有时候主引导程序的一些段和内核段是可以共用的(事实上加载完内核以后 ...
- 敏捷软件开发:原则、模式与实践——第13章 写给C#程序员的UML概述
第13章 写给C#程序员的UML概述 UML包含3类主要的图示.静态图(static diagram)描述了类.对象.数据结构以及它们之间的关系,藉此表现出了软件元素间那些不变的逻辑结构.动态图(dy ...
- 第13章 Salesforce Lightning应用程序
13.1 Lightning应用程序 13.1.1 什么是闪电应用程序 Salesforce应用程序有两种风格:经典应用程序和闪电应用程序.经典应用程序在Salesforce Classic中创建和管 ...
- Linux就这个范儿 第13章 打通任督二脉
Linux就这个范儿 第13章 打通任督二脉 0111010110……你有没有想过,数据从看得见或看不见的线缆上飞来飞去,是怎么实现的呢?数据传输业务的未来又在哪里?在前面两章中我们学习了Linux网 ...
- 《Android开发艺术探索》读书笔记 (13) 第13章 综合技术、第14章 JNI和NDK编程、第15章 Android性能优化
第13章 综合技术 13.1 使用CrashHandler来获取应用的Crash信息 (1)应用发生Crash在所难免,但是如何采集crash信息以供后续开发处理这类问题呢?利用Thread类的set ...
- 【STM32H7教程】第13章 STM32H7启动过程详解
完整教程下载地址:http://forum.armfly.com/forum.php?mod=viewthread&tid=86980 第13章 STM32H7启动过程详解 本章教 ...
- 【RL-TCPnet网络教程】第13章 RL-TCPnet之TCP服务器
第13章 RL-TCPnet之TCP服务器 本章节为大家讲解RL-TCPnet的TCP服务器实现,学习本章节前,务必要优先学习第12章TCP传输控制协议基础知识.有了这些基础知识之后,再搞本 ...
随机推荐
- 黑马程序员_ Objective-c 之Foundation笔记(二)
NSArray NSArray的创建 NSArray *array = [NSArray arrayWithObject:@“jack”] 创建单个元素 NSArray *array3 = [NS ...
- eworkflow工作流系统在iis中发布
eworkflow工作流系统在iis中发布 win7下面的iis发布eworkflow工作流系统,要带虚拟目录的,如发布成http://localhost/eworkflow/login.aspx这样 ...
- SQL Server 2008数据库日志收缩
GO ALTER DATABASE MCS SET RECOVERY SIMPLE--设置简单恢复模式 GO DBCC SHRINKFILE (MCS_Log, 1) GO ALTER DATABAS ...
- js实现图片无缝连接
效果图 1.首先先看看html和css代码 <style> *{padding:0;margin:0;} #div1{margin:100px auto;background:red;wi ...
- 使用yum安装应用程序时候,报错:[Errno 14] PYCURL ERROR 7 - "Failed to connect to 2001:da8:8000:6023::230: 网络不可达"
使用yum安装应用程序时候,报错:[Errno 14] PYCURL ERROR 7 - "Failed to connect to 2001:da8:8000:6023::230: 网络不 ...
- rt—移植笔记1
将rtt源码往stm32f407移植的时候,源码串口打印引脚设置有误,以下是源码引脚配置. 以下是原理图 可见配置有误.
- RedHat6.5更新软件源
今天在Red Hat上安装软件时,发现需要依赖软件,然而在用sudo yum指令时,出现了下面的错误: This system is not registered to Red Hat Subscri ...
- disconf系列【1】——百度disconf在ubuntu14.04环境下的安装
disconf官网给出的安装文档默认读者已经非常熟练本文1.2章节给出的依赖软件的原理及使用方法,且官网默认安装环境为linux(windows安装方法只字未提).同时,官网对很多重要的细节语焉不详, ...
- RX(Reactive Extinsion)和IX(Interactive Extinsion)库改名了
RX和IX库是我经常用到的库,今天写一个小程序的时候想用IX库的时候,发现却找不到了.在它的源码的网站上找了一下,发现它们被改名了,具体的变化为为: 对于RX库: Rx-Main -> Syst ...
- XidianOJ 1149 卡尔的技能 II
--正文 多重集合数 + 组合数取模 首先求出没有限制的选择方法C(n+m-1,m) 然后减掉至少有一个元素选择了k+1次的方法数,加上至少有两个元素选择了k+1次的方法数...以此类推 然后是组合数 ...