第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传输控制协议基础知识.有了这些基础知识之后,再搞本 ...
随机推荐
- python 2day
一 优化 username='alex' password=‘alex123’ 可以写成 username,password =‘alex’,'alex123' 二.再次优化 for i in ran ...
- 批量删除wps文档里的回车符的方法!WPS使用技巧分享!
有时候整理文档的时候,如果是从网上复制的文字,可能会因为复制而产生很多的回车符.怎样能批量去掉这些个回车符呢,下面马上告诉你批量删除wps文档里的回车符的方法!WPS使用技巧分享! 想要批量删除批量删 ...
- Redis安装手册
转载请注明出处:http://www.cnblogs.com/robinjava77/p/5465146.html (Robin) 1)下载redis:wget http://download.red ...
- Scorpio-CSharp总链接
简介 源码目录介绍
- 关于Python3爬虫抓取网页Unicode
import urllib.requestresponse = urllib.request.urlopen('http://www.baidu.com')html = response.read() ...
- 类的高级:访问修饰符、封装、静态类成员static、内部类;
访问修饰符: 公开访问(public):对所有子类,非子类访问: 受保护的(protected):只有同包子类.非子类.不同包子类可访问,不同包非子类不可访问: 私有的(private):只有本类可访 ...
- jQuery 插件基础
jQuery 插件基础 翻译 How to Create a Basic Plugin 如果你需要在 jQuery 选择器上执行一系列重复操作, 这时候你需要编写 jQuery 插件. jQuery ...
- PS 使用首记 修改png图片的颜色
ps打开png图片文件 改颜色 1.魔棒工具,选择图片中的圆圈或方框,双击,选中,出现蚂蚁线. 2.右侧调好颜色 3.alt+delete颜色就改成功了.保存ok. 吸管工具,吸到颜色,存到色板.需要 ...
- Vagrant的一个BUG - 不支持'change_host_name'
==> master: Setting hostname... Vagrant attempted to execute the capability 'change_host_name' on ...
- Activity has leaked window that was originally added
错误: E/WindowManager: android.view.WindowLeaked: Activity com.x.x.x has leaked window com.android.int ...