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文件 配置类的集合的更多相关文章

  1. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

  2. 读取Config文件工具类 PropertiesConfig.java

    package com.util; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io ...

  3. SSH自动登录config文件配置

    title: SSH自动登录config文件配置 comments: false date: 2019-08-19 19:29:13 description: 更方便的 ssh 操作??? categ ...

  4. 通过config文件配置动态导入模块

    需求: 固定的服务中要调用不同的算法,当前服务中实现的动态导入是通过在config配置中加上参数:proto="AiProto(1,4)",在服务中from pathname im ...

  5. C# app.config文件配置和修改

    很多时候我们需要对系统的.config文件进度读写操作,例如:系统初始化的参数的更改.系统参数的改变都需要更新到配置文件. 首先我们有必要了解一下app.config.exe.config和vshos ...

  6. 跨域Ajax请求 web.config文件配置

    在web.config文件的<system.webServer>节点下面添加如下配置代码:<!--允许跨域ajax访问--> <httpProtocol> < ...

  7. Web.Config文件配置之限制上传文件大小和时间

    在邮件发送系统或者其他一些传送文件的网站中,用户传送文件的大小是有限制的,因为这样不但可以节省服务器的空间,还可以提高传送文件的速度.下面介绍如何在Web.Config文件中配置限制上传文件大小与时间 ...

  8. Winform数据库连接app.config文件配置

    1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...

  9. Winform 数据库连接app.config文件配置 数据库连接字符串

    1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...

随机推荐

  1. consumer group

    Kafka消费组(consumer group)一直以来都想写一点关于kafka consumer的东西,特别是关于新版consumer的中文资料很少.最近Kafka社区邮件组已经在讨论是否应该正式使 ...

  2. saltstack安装配置(halite)

    saltstack官方提供了一个简单的web UI--halite.但是给出的安装配置方法实在没法实现,在网上找了几篇博客,见文章末尾的参考链接,可以用起来了.但是功能有点简单.这篇文章记录安装配置h ...

  3. python install

    Install all dependencies by pip install -r requirements.txt (Run this command from project root)

  4. 为easyui datagrid 添加上下方向键移动

    将以下脚本保存为 easyui-datagrid-moverow.js var DatagridMoveRow = (function($){ function DatagridMoveRow(gri ...

  5. SlideAndDragListView,一个可排序可滑动item的ListView

    SlideAndDragListView简介 SlideAndDragListView,可排序.可滑动item显示"菜单"的ListView. SlideAndDragListVi ...

  6. 跟我学习Storm_Storm基本架构

    Storm集群类似于一个Hadoop集群. 然而你在Hadoop的运行“MapReduce job”,在Storm上你运行 “topologies”. “job”和“topologies”本身有很大的 ...

  7. express:webpack dev-server中如何将对后端的http请求转到https的后端服务器中?

    在上一篇文章(Webpack系列:在Webpack+Vue开发中如何调用tomcat的后端服务器的接口?)我们介绍了如何将对于webpack-dev-server的数据请求转发到后端服务器上,这在大部 ...

  8. php-fpm 启动参数及重要配置详解

    约定几个目录 /usr/local/php/sbin/php-fpm /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php.ini 一,php- ...

  9. js的bind方法

    转载:http://www.jb51.net/article/94451.htm http://www.cnblogs.com/TiestoRay/p/3360378.html https://seg ...

  10. [BZOJ3714][PA2014]Kuglarz(MST)

    题目: Description 魔术师的桌子上有n个杯子排成一行,编号为1,2,…,n,其中某些杯子底下藏有一个小球,如果你准确地猜出是哪些杯子,你就可以获得奖品.花费c_ij元,魔术师就会告诉你杯子 ...