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应用程序配置的更多相关文章

  1. 鸟哥的Linux私房菜-第10/11/12/13章(vim程序编辑器、学习bash、正则表达式与文件格式化处理、学习Shell Scripts)

    第10章 vim程序编辑器 可以将vim看做vi的进阶版本,vim可以用颜色或底线等方式来显示出一些特殊的信息. 为何要学习vim?因为: a. 所有的 Unix Like 系统都会内建 vi 文书编 ...

  2. sql server 2000安装程序配置服务器失败

    第一种方法 今天安装SQL Server 2000遇到了个很BT的问题,提示出下: 安装程序配置服务器失败.参考服务器错误日志和C:\Windows\sqlstp.log了解更多信息. 以前进安装目录 ...

  3. ASM:《X86汇编语言-从实模式到保护模式》第13章:保护模式下内核的加载,程序的动态加载和执行

    ★PART1:32位保护模式下内核简易模型 1. 内核的结构,功能和加载 每个内核的主引导程序都会有所不同,因为内核都会有不同的结构.有时候主引导程序的一些段和内核段是可以共用的(事实上加载完内核以后 ...

  4. 敏捷软件开发:原则、模式与实践——第13章 写给C#程序员的UML概述

    第13章 写给C#程序员的UML概述 UML包含3类主要的图示.静态图(static diagram)描述了类.对象.数据结构以及它们之间的关系,藉此表现出了软件元素间那些不变的逻辑结构.动态图(dy ...

  5. 第13章 Salesforce Lightning应用程序

    13.1 Lightning应用程序 13.1.1 什么是闪电应用程序 Salesforce应用程序有两种风格:经典应用程序和闪电应用程序.经典应用程序在Salesforce Classic中创建和管 ...

  6. Linux就这个范儿 第13章 打通任督二脉

    Linux就这个范儿 第13章 打通任督二脉 0111010110……你有没有想过,数据从看得见或看不见的线缆上飞来飞去,是怎么实现的呢?数据传输业务的未来又在哪里?在前面两章中我们学习了Linux网 ...

  7. 《Android开发艺术探索》读书笔记 (13) 第13章 综合技术、第14章 JNI和NDK编程、第15章 Android性能优化

    第13章 综合技术 13.1 使用CrashHandler来获取应用的Crash信息 (1)应用发生Crash在所难免,但是如何采集crash信息以供后续开发处理这类问题呢?利用Thread类的set ...

  8. 【STM32H7教程】第13章 STM32H7启动过程详解

    完整教程下载地址:http://forum.armfly.com/forum.php?mod=viewthread&tid=86980 第13章       STM32H7启动过程详解 本章教 ...

  9. 【RL-TCPnet网络教程】第13章 RL-TCPnet之TCP服务器

    第13章      RL-TCPnet之TCP服务器 本章节为大家讲解RL-TCPnet的TCP服务器实现,学习本章节前,务必要优先学习第12章TCP传输控制协议基础知识.有了这些基础知识之后,再搞本 ...

随机推荐

  1. LeetCode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  2. [转] 主流JS框架中DOMReady事件的实现

    在实际应用中,我们经常会遇到这样的场景,当页面加载完成后去做一些事情:绑定事件.DOM操作某些结点等.原来比较常用的是window的onload 事件,而该事件的实际效果是:当页面解析/DOM树建立完 ...

  3. Win8.1安装Visual Studio 2015提示需要KB2919355

    http://www.microsoft.com/zh-cn/download/details.aspx?id=42335 安装说明: 1.若要开始下载,请单击“下载”按钮,然后执行以下操作之一,或者 ...

  4. 使用Maven加载项目有Dubbo框架时出现的常见异常情况

    异常描述:            The matching wildcard is strict, but no declaration can be found for element 'dubbo ...

  5. C++注意

    断言assert是仅在Debug版本起作用的宏,它用于检查“不应该”发生的情况. 在函数的入口处,使用断言检查参数的有效性(合法性). 如果程序在assert处终止了,并不是说含有该assert的函数 ...

  6. loadrunner录制脚本如何选择使用get请求和post请求的方式

    在loadrunner工具里录制脚本时常常会用到get请求和post请求,有关loadrunner常用的这两类的请求主要有: get请求: web_url 和 web_link post请求: web ...

  7. 用OSSIM轻松分析网络设备日志

    用OSSIM轻松分析网络设备日志 基于插件的日志收集与处理模式,使得用户可以轻松的利用OSSIM来分析异构网络环境下的各种网络设备日志,下面展示一些硬件设备日志的实例,我们在RAW LOG界面里,搜索 ...

  8. EL表达式显示数据取整问题

    第一 插入fmt标签库 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%&g ...

  9. 父进程等待子进程结束 waitpid wait

    我们一直在强调一个概念就是进程是一个程序执行的实例,是内核在虚拟概念下创建的实体,它实例化的体现在用户态就是程序代码和代码使用的变量(存储空间),在内核态就是内核为我们每个进程所保存的数据结构(状态信 ...

  10. 转载-V.I.Arnold, beyond a mathematician

    转自-http://blog.renren.com/blog/248100754/471276636 在AMS的首页上找到了三条讣告,依次是V.I.Arnold(1937-2010),W.Rudin( ...