.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 ...
随机推荐
- ios7 tableview scrollsToTop 不执行处理方法
ios7中调用[self.tableview scrollsToTop] 没有效果(ios8中也没有效果) stackflow 处理方法: [self.tableviewscrollRectToVis ...
- Ehcache和Spring整合
Ehcache是使用Java编写的缓存框架,比较常用的是,整合在Hibernate和MyBatis这种关系型数据库持久框架. 不过现在用NoSQL也比较盛行,要应用Ehcache,整合起来就没法按照那 ...
- (WPF) 基本题
What is WPF? WPF (Windows Presentation foundation) is a graphical subsystem for displaying user inte ...
- PICT安装与使用
一.PICT简介 PICT工具是在微软公司推出的一款成对组合的命令行生成工具,下载地址http://download.microsoft.com/download/f/5/5/f55484df-849 ...
- pyqt5安装
花了一天时间,终于是装好了. 这东西硬是把我从Python2掰弯成了Python3 本来用pip安装了一个pyqt,但是后来才发现,这是个x64版本的. 我不知道啊! 我以为是还要装qt5 所以我把q ...
- Android Studio in OSX 提高工作效率的快捷键
前言 本篇文章参考了<倍数提高工作效率的Android Studio>一文,快捷键基于OS X系统. OS X Yosemite 10.10.5 Android Studio 1.3.1 ...
- 规则引擎集成接口(七)规则引擎调用Java类
规则引擎调用Java类 通过myEclipse编写一个简单工程,其中方法是两数相加等到结果,既结果1=输入值1+输入值2.实现规则调用外部接口的方法有三种. 1:接口实例:在myEclipse中制作一 ...
- tracert-命令小结
前言:今天在阅读“Web性能权威指南”这本书的时候,发现 tracert 这个命令挺有意思的,在分析网络性能瓶颈的时候也能使用的到,在此就小记一笔以备后用. 1:作用 tracert 是一 ...
- ASP.NET权限管理
ASP.NET Web Forms权限管理: 我要将一个文件夹只能让一个用户组访问怎么办? 可否在网站根目录下的web.config里这样设置: <location path="adm ...
- 2016-11-10:win7下VMware虚拟机中CentOS6.5网络配置
在win7环境下,使用桥接和NAT模式配置VMware虚拟机网络,实现宿主机与虚拟机以及虚拟机通过宿主机网卡访问互联网. 1 配置VMware虚拟网络编辑器 VMnet0 桥接模式 VMnet1仅主机 ...