.NET 配置项扩展
using System;
using System.Configuration; namespace ConsoleApplication3
{
/*
web.config 或 app.config 中的配置示例如下(注:configSections 节一定要是 configuration 节下的第一个元素): <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="urls" type="ConsoleApplication3.EasConfigurationSection, ConsoleApplication3"/>
</configSections> <urls>
<url name="cn.bing.com" url="http://cn.bing.com/" port="80"></url>
</urls>
</configuration>
*/ public class EasConfigurationElement : ConfigurationElement
{
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
public string Name
{
get { return (string)this["name"]; }
set { this["name"] = value; }
} [ConfigurationProperty("url", DefaultValue = "")]
public string Url
{
get { return (string)this["url"]; }
set { this["url"] = value; }
} [ConfigurationProperty("port", DefaultValue = , IsRequired = false)]
[IntegerValidator(MinValue = , MaxValue = , ExcludeRange = false)]
public int Port
{
get { return (int)this["port"]; }
set { this["port"] = value; }
}
} [ConfigurationCollection(typeof(EasConfigurationElement))]
public class EasConfigurationElementCollection : ConfigurationElementCollection
{
protected override string ElementName
{
get
{
return "url";
}
} public override ConfigurationElementCollectionType CollectionType
{
get { return ConfigurationElementCollectionType.BasicMap; }
} protected override ConfigurationElement CreateNewElement()
{
return new EasConfigurationElement();
} protected override object GetElementKey( ConfigurationElement element )
{
var newElement = element as EasConfigurationElement; if( newElement != null ) return newElement.Name; throw new NullReferenceException( "element can not convert to " + typeof( EasConfigurationElement ) );
} public EasConfigurationElement this[ int index ]
{
get { return (EasConfigurationElement)BaseGet( index ); }
set
{
if( BaseGet( index ) != null )
{
BaseRemoveAt( index );
} BaseAdd( index, value );
}
}
} public class EasConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("", IsDefaultCollection = true)]
public EasConfigurationElementCollection Urls
{
get
{
var collection = (EasConfigurationElementCollection)base[""]; return collection;
}
}
}
}
.NET 配置项扩展的更多相关文章
- form-create 3.0 版本发布,好用的Vue3版本动态表单生成组件
form-create 是一个可以通过 JSON 生成具有动态渲染.数据收集.验证和提交功能的表单生成组件.支持2个UI框架,并且支持生成任何 Vue 组件.内置20种常用表单组件和自定义组件,再复杂 ...
- 大数据系统之监控系统(二)Flume的扩展
一些需求是原生Flume无法满足的,因此,基于开源的Flume我们增加了许多功能. EventDeserializer的缺陷 Flume的每一个source对应的deserializer必须实现接口E ...
- JSHint配置项说明
转自:http://www.jianshu.com/p/4cb23f9e19d3 什么是JSHint? 官方网站这样介绍: JSHint, A Static Code Analysis Tool fo ...
- validate插件深入学习-03validate()方法配置项
validate()方法配置项 rules 定义校验规则 messages 定义提示信息 上面这两个已经介绍过了 rules里隐藏的属性depends,只有符合条件(返回true)的时候才会执行 su ...
- PHP扩展编写、PHP扩展调试、VLD源码分析、基于嵌入式Embed SAPI实现opcode查看
catalogue . 编译PHP源码 . 扩展结构.优缺点 . 使用PHP原生扩展框架wizard ext_skel编写扩展 . 编译安装VLD . Debug调试VLD . VLD源码分析 . 嵌 ...
- thinkphp 行为扩展以及插件机制介绍
首先行为扩展这个概念是TP架构的核心组成之一,关于行为的解释我就粗略的概括一下吧:TP在从接受到HTTP请求到最终将视图输出,期间经历的很多步骤,这些步骤大家可以在http://document.th ...
- 基于Spring的可扩展Schema进行开发自定义配置标签支持
一.背景 最近和朋友一起想开发一个类似alibaba dubbo的功能的工具,其中就用到了基于Spring的可扩展Schema进行开发自定义配置标签支持,通过上网查资料自己写了一个demo.今天在这里 ...
- 【转】VS项目属性的一些配置项的总结
首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件夹以及解决方案和各个项目对应的配置文件包含关系,假设新建一个项目ssyy,解决方案起名fangan,注意解决方案包括项目, ...
- 【转】Hive配置文件中配置项的含义详解(收藏版)
http://www.aboutyun.com/thread-7548-1-1.html 这里面列出了hive几乎所有的配置项,下面问题只是说出了几种配置项目的作用.更多内容,可以查看内容问题导读:1 ...
随机推荐
- IE8、IE9浏览器下报:JSON未定义 解决方法
IE8.IE9浏览器下报:JSON未定义的问题 解决方法: 在jsp中引入如下代码 <!-- 解决 IE8.IE9 下显示混乱的问题--><% String browserStrin ...
- DNS错误 事件4000 4013
DNS 错误事件4000 4013,无法创建活动目录本身的区域 WINDOWS 2003 DNS服务器无法解析 错误ID 4000 DNS 服务器无法打开 Active Directory.这台 DN ...
- VS2010 AppCode文件夹问题
在Web应用程序中不能通过右键项目-〉”添加“-〉”添加ASP.NET文件夹“方式添加 .因为Web应用程序中App_Code就不存在 .不过可以通过手动的方式创建,添加一个文件夹命名为App_Cod ...
- C#矩阵运算类库
这个类库是本人参考许多相关资料之后做出的C#矩阵运算类库,因为C#的数值计算库相对比较少,所以希望这个类库能够给大家带来一些帮助. 源码github网址:https://github.com/Josh ...
- VS2015 使用Razor编写MVC视图时,Razor智能提示消失,报各种红线解决方案。
打开文件夹 Users\<CurrentUser>\AppData\Local\Microsoft\VisualStudio\<version> 删除文件夹 Component ...
- 搭建jms的步骤和过程
搭建jms 参考网摘: http://www.jianshu.com/p/98689164a041
- 带你入门带你飞Ⅱ 使用Mocha + Chai + SuperTest测试Restful API in node.js
目录 1. 简介 2. 准备开始 3. Restful API测试实战 Example 1 - GET Example 2 - Post Example 3 - Put Example 4 - Del ...
- Linux disk_partition_dev_马士兵_note
一般装Linux会遇到的问题: 找不到硬件驱动 现在主流的一些硬件 不支持Linux驱动 尽量找主流的硬件,尽量找老一点的硬件 装系统: 1.记下 系统 ---->到时候要找驱动 2 ...
- SQL Server选项综述
I. 基本概念 SQL Server中的选项根据其作用范围分为如下几类: 实例选项 —— 在数据库实例范围内有效,通过 sp_configure 存储过程进行配置. 数据库选项 —— 在数据库范围内有 ...
- 01-C#入门(分支控制语句)
说实话,<C#入门经典>这本书对入门的同学来说真的太棒了,先不说内容如何,就作者先以控制台(命令行)调试程序的方法,就能够最大限度地让你关注学习的内容,而不是花哨的界面调试. 现在学习是下 ...