.net config文件 配置类的集合
1,appconfig文件
<configSections>
<section name="ToolConfig" type="DMTools.ToolConfigSection,DMTools"/>
</configSections>
<ToolConfig >
<DmTools>
<AddTool ImagePath="pic\MapGen.png" Name="代码生成By设计文档" Link="http://dmsite.chinacloudsites.cn/root/tools/CodeGenBySql/CodeGenBySql.application" />
<AddTool ImagePath="pic\CodeGenBySql.png" Name="代码生成BySQl" Link="http://dmsite.chinacloudsites.cn/root/tools/CodeGenBySql/CodeGenBySql.application" />
<AddTool ImagePath="pic\SyncDataBase.png" Name="数据结构迁移工具" Link="http://dmsite.chinacloudsites.cn/root/Tools/SysDataBase/SyncDataBase.application" />
<AddTool ImagePath="pic\MegreFile.png" Name="SQL自动合并执行工具" Link="http://dmsite.chinacloudsites.cn/root/Tools/MegreFile/MegreFile.application" />
</DmTools>
</ToolConfig>
2,配置类
namespace DMTools
{ public class ToolConfigSection : ConfigurationSection
{
[ConfigurationProperty("DmTools")] [ConfigurationCollection(typeof(DmToolConfigurationElementCollection), AddItemName = "AddTool", ClearItemsName = "ClearTool", RemoveItemName = "RemoveTool")]
public DmToolConfigurationElementCollection DmToolElements
{
get { return (DmToolConfigurationElementCollection)this["DmTools"]; }
set { this["DmTools"] = value; }
}
} public class DmToolConfigurationElementCollection : ConfigurationElementCollection
{
// 基本上,所有的方法都只要简单地调用基类的实现就可以了。 public DmToolConfigurationElementCollection() : base(StringComparer.OrdinalIgnoreCase) // 忽略大小写
{
} // 其实关键就是这个索引器。但它也是调用基类的实现,只是做下类型转就行了。
new public DmToolConfigurationElement this[string name]
{
get
{
return (DmToolConfigurationElement)base.BaseGet(name);
}
} // 下面二个方法中抽象类中必须要实现的。
protected override ConfigurationElement CreateNewElement()
{
return new DmToolConfigurationElement();
} protected override object GetElementKey(ConfigurationElement element)
{
return ((DmToolConfigurationElement)element).Name;
} // 说明:如果不需要在代码中修改集合,可以不实现Add, Clear, Remove
public void Add(DmToolConfigurationElement setting)
{
this.BaseAdd(setting);
}
public void Clear()
{
base.BaseClear();
}
public void Remove(string name)
{
base.BaseRemove(name);
}
} public class DmToolConfigurationElement : ConfigurationElement // 集合中的每个元素
{
[ConfigurationProperty("ImagePath", IsRequired = true)]
public string ImagePath
{
get { return this["ImagePath"].ToString(); }
set { this["ImagePath"] = value; }
} [ConfigurationProperty("Name", IsRequired = true)]
public string Name
{
get { return this["Name"].ToString(); }
set { this["Name"] = value; }
}
[ConfigurationProperty("Link", IsRequired = true)]
public string Link
{
get { return this["Link"].ToString(); }
set { this["Link"] = value; }
}
}
}
3,代码使用
ToolConfigSection toolSection= (ToolConfigSection)ConfigurationManager.GetSection("ToolConfig");
lstTile = (from toolElement in toolSection.DmToolElements.Cast<DmToolConfigurationElement>()
select new Tile { Name = toolElement.Name, Link = toolElement.Link, ImagePath = toolElement.ImagePath }
).ToList();
.net config文件 配置类的集合的更多相关文章
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...
- 读取Config文件工具类 PropertiesConfig.java
package com.util; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io ...
- SSH自动登录config文件配置
title: SSH自动登录config文件配置 comments: false date: 2019-08-19 19:29:13 description: 更方便的 ssh 操作??? categ ...
- 通过config文件配置动态导入模块
需求: 固定的服务中要调用不同的算法,当前服务中实现的动态导入是通过在config配置中加上参数:proto="AiProto(1,4)",在服务中from pathname im ...
- C# app.config文件配置和修改
很多时候我们需要对系统的.config文件进度读写操作,例如:系统初始化的参数的更改.系统参数的改变都需要更新到配置文件. 首先我们有必要了解一下app.config.exe.config和vshos ...
- 跨域Ajax请求 web.config文件配置
在web.config文件的<system.webServer>节点下面添加如下配置代码:<!--允许跨域ajax访问--> <httpProtocol> < ...
- Web.Config文件配置之限制上传文件大小和时间
在邮件发送系统或者其他一些传送文件的网站中,用户传送文件的大小是有限制的,因为这样不但可以节省服务器的空间,还可以提高传送文件的速度.下面介绍如何在Web.Config文件中配置限制上传文件大小与时间 ...
- Winform数据库连接app.config文件配置
1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...
- Winform 数据库连接app.config文件配置 数据库连接字符串
1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...
随机推荐
- 假设检验:p-value,FDR,q-value
来源:http://blog.sina.com.cn/s/blog_6b1c9ed50101l02a.html,http://wenku.baidu.com/link?url=3mRTbARl0uPH ...
- Java 集合系列16之 HashSet详细介绍(源码解析)和使用示例
概要 这一章,我们对HashSet进行学习.我们先对HashSet有个整体认识,然后再学习它的源码,最后再通过实例来学会使用HashSet.内容包括:第1部分 HashSet介绍第2部分 HashSe ...
- 【MySql】存储过程添加事务
存储过程使用SQLException捕获SQL错误,然后处理: 我们可以在MySQL存储过程中捕获SQL错误,然后通过事务判断,回滚(ROLLBACK)还是提交(COMMIT). CREATE PRO ...
- Padrino 生成器指南
英文版出处:http://www.padrinorb.com/guides/generators Padrino提供了用于快速创建应用的生成器,其优势在于构建推荐的Padrino应用结构.自动生成罗列 ...
- single-write-database-connection
http://ithare.com/ultimate-db-heresy-single-db-connection-part-i-performance-part-ii-scalability-to- ...
- 2013级软件工程GitHub账号信息
GitHub账号信息 序号 班级 学号 姓名 个人GitHub网址 1 信1301-1班 20122951 刘伟 https://github.com/weige8882 2 信1301-1班 201 ...
- Java中primitive type的线程安全性
Java中primite type,如char,integer,bool之类的,它们的读写操作都是atomic的,但是有几个例外: long和double类型不是atomic的,因为long和doub ...
- 【AS3】Flash与后台数据交换四种方法整理
随着Flash Player 9的普及,AS3编程也越来越多了,所以这次重新整理AS3下几种与后台数据交换方法.1.URLLoader(URLStream)2.FlashRemoting3.XMLSo ...
- mvc5+ef6+Bootstrap 项目心得--WebGrid
1.mvc5+ef6+Bootstrap 项目心得--创立之初 2.mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理 3.mvc5+ef6+Bootstrap 项目心得--WebG ...
- 纯C#实现Hook功能
发布一个自己写的用于Hook .Net方法的类库,代码量不大,完全的C#代码实现,是一个比较有趣的功能,分享出来希望能和大家共同探讨 安装:Install-Package DotNetDetour源码 ...