.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 ...
随机推荐
- Jenkins若干小问题
1. Jenkins上不能直接在shell中调用scp命令来执行上传下载操作,核心问题是scp需要输入密码. 为了可以直接将密码传递过去.我们安装 sshpass 来透传密码 a. 安装sshpas ...
- Linux通过NAT方式配置网络
步骤:1.将虚拟机的网卡VMware Network Adapter VMnet8改成DHCP自动获取IP.2.将Linux虚拟机的网卡自定义连接到VMware Network Adapter VMn ...
- Async Programming - 1 async-await 糖的本质(2)
上一篇讲了这么多,其实说的就是一个事,return会被编译器重写成SetResult,所以如果我们的异步函数返回的是一个Task<int>,代码就要改成这样: using System; ...
- DevExpress TreeList 全选和反选 z
/// <summary> /// 全选树 /// </summary> /// <param name="tree">树控件</para ...
- 百度地图API功能集锦
1.点个数太多导致加载缓慢的解决. 2.可视化区域内加载的解决. 3.自定义信息窗口解决. 4.区域/板块/商圈等的绘制功能解决. 基本包含了用到百度地图API会使用到的大部分常规性场景.(聚合点功能 ...
- delphi cmd
今天看到有人在问用代码执行CMD命令的问题,就总结一下用法,也算做个备忘. Delphi中,执行命令或者运行一个程序有2个函数,一个是winexec,一个是shellexecute.这两个大家应该都见 ...
- gpio高阻态
配置gpio为高阻态:将gpio设为GPIO_INPUT,GPIO_NO_PULL即可
- UVA 11853 [dfs乱搞]
/* 大连热身E题 不要低头,不要放弃,不要气馁,不要慌张 题意: 在1000×1000的格子内有很多个炮弹中心,半径给定. 为某人能否从西部边界出发,从东部边界走出. 不能输出不能,能的话输出最北边 ...
- 【HOW】如何手工编辑InfoPath文件
因为直接打开InfoPath的配置文件进行编辑会有些无从下手,所以下面以修改“节”的Margin为例来说明手工编辑InfoPath文件的过程. 1. 新建一个“节”,并在此节中创建一个数字类型字段“n ...
- php面向对象学习笔记
PHP 面向对象技术(全面讲解) Ø 主要内容 v 1.面向对象的概念 v 2.什么是类,什么是对象,类和对象之间的关系 v 3.什么是面向对象编程呢? v 4.如何抽象出一个类? v 5.如何实例化 ...