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 配置项扩展的更多相关文章

  1. form-create 3.0 版本发布,好用的Vue3版本动态表单生成组件

    form-create 是一个可以通过 JSON 生成具有动态渲染.数据收集.验证和提交功能的表单生成组件.支持2个UI框架,并且支持生成任何 Vue 组件.内置20种常用表单组件和自定义组件,再复杂 ...

  2. 大数据系统之监控系统(二)Flume的扩展

    一些需求是原生Flume无法满足的,因此,基于开源的Flume我们增加了许多功能. EventDeserializer的缺陷 Flume的每一个source对应的deserializer必须实现接口E ...

  3. JSHint配置项说明

    转自:http://www.jianshu.com/p/4cb23f9e19d3 什么是JSHint? 官方网站这样介绍: JSHint, A Static Code Analysis Tool fo ...

  4. validate插件深入学习-03validate()方法配置项

    validate()方法配置项 rules 定义校验规则 messages 定义提示信息 上面这两个已经介绍过了 rules里隐藏的属性depends,只有符合条件(返回true)的时候才会执行 su ...

  5. PHP扩展编写、PHP扩展调试、VLD源码分析、基于嵌入式Embed SAPI实现opcode查看

    catalogue . 编译PHP源码 . 扩展结构.优缺点 . 使用PHP原生扩展框架wizard ext_skel编写扩展 . 编译安装VLD . Debug调试VLD . VLD源码分析 . 嵌 ...

  6. thinkphp 行为扩展以及插件机制介绍

    首先行为扩展这个概念是TP架构的核心组成之一,关于行为的解释我就粗略的概括一下吧:TP在从接受到HTTP请求到最终将视图输出,期间经历的很多步骤,这些步骤大家可以在http://document.th ...

  7. 基于Spring的可扩展Schema进行开发自定义配置标签支持

    一.背景 最近和朋友一起想开发一个类似alibaba dubbo的功能的工具,其中就用到了基于Spring的可扩展Schema进行开发自定义配置标签支持,通过上网查资料自己写了一个demo.今天在这里 ...

  8. 【转】VS项目属性的一些配置项的总结

    首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件夹以及解决方案和各个项目对应的配置文件包含关系,假设新建一个项目ssyy,解决方案起名fangan,注意解决方案包括项目, ...

  9. 【转】Hive配置文件中配置项的含义详解(收藏版)

    http://www.aboutyun.com/thread-7548-1-1.html 这里面列出了hive几乎所有的配置项,下面问题只是说出了几种配置项目的作用.更多内容,可以查看内容问题导读:1 ...

随机推荐

  1. VS2013,VS2015设置类模板文件表头

    一般VS的类模板文件是放在C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplatesCache\CSha ...

  2. Flask最佳实践

    https://zhuanlan.zhihu.com/p/22774028?refer=python-cn

  3. css3画三角形的原理

    以前用过css3画过下拉菜单里文字后面的“下拉三角符号”,类似于下面这张图片文字后面三角符号的效果 下面是一个很简单的向上的三角形代码 #triangle-up { width: 0; height: ...

  4. Java实现购物车功能:方式一:存放在session中.方式二:存储在数据库中

    //将购物车产品加入到cookie中,方式同浏览记录.Java实现购物车,方式一(简易版):存储在session中.这种方式实现还不严谨,大家看的时候看思路即可.(1). JSP页面中,选择某一款产品 ...

  5. (转)打印相关_C#图片处理Bitmap位图缩放和剪裁

    原文地址:http://blog.sina.com.cn/s/blog_6427a6b50101el9d.html 在GDI+中,缩放和剪裁可以看作同一个操作,无非就是原始区域的选择不同罢了. /// ...

  6. [python实现设计模式]-5.迭代器模式-一起撸串嗨皮啦

    迭代器模式是一个我们经常使用但是出境不高的模式. 为啥捏?因为大部分的语言都帮我们实现了细节,我们不许关注他的实现就能用的很嗨皮了. 不管怎样.这也是个非常常用的模式. 俗话说得好,这个世界上没有事情 ...

  7. Proe Top-Down设计演示

    前段时间有网友问我,proe 里面有没有装配设计中当某一零件尺寸需要修改时, 与其相关的零件尺寸都需要随之做相应改变的法子.我认为top-down是很好的选择. 下面介绍一下top-down的理论: ...

  8. php SimpleXML 例子

    $txt = GetRemoteText($url); if(strlen($txt) > 0) { $xml = simplexml_load_string($txt); //获取xml if ...

  9. 【练习】数据移动---导出(EXPDP)

    1.导出表: [oracle@host03 datadump]$ expdp scott/tiger directory=dir_dp dumpfile=emp.dmp tables=emp; Exp ...

  10. C#中操作Word(1)—— word对象模型介绍

    一.开发环境布置 C#中添加对Word的支持,只需添加对Microsoft.Office.Interop.Word的命名空间,如下图所示,右键点击“引用”,在弹出的“添加引用”对话框中选中COM标签页 ...