C# config配置文件 读取

news/2024/9/22 21:02:28/
<?xml version="1.0" encoding="utf-8" ?>
<configuration><configSections><section name="deviceFieldConfig" type="ConfigurationSectionDemo.DeviceFieldonfig,ConfigurationSectionDemo" /></configSections><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /></startup><deviceFieldConfig deviceCode = "BC2D00"><fields><!--2D 水平补偿--><add fieldName="BCSP2D" fieldId="10032"/><!--2D 垂直补偿--><add fieldName="BCCZ2D" fieldId="10033"/><!--2D 倾角补偿--><add fieldName="BCQJ2D" fieldId="10034"/><!--2D 外轨超高--><add fieldName ="BCWG2D" fieldId="10035"/><!--检测时间--><add fieldName ="JCJCSJ" fieldId="10065"/></fields></deviceFieldConfig></configuration>
//使用自定义节点,可能会涉及到这几个对象的使用://ConfigurationSection【配置域】、//    ConfigurationElement【节点】、//    ConfigurationElementCollection【节点列表】public class DeviceFieldonfig : ConfigurationSection{[ConfigurationProperty("deviceCode", IsRequired = true)]public string DeviceCode { get { return (string)base["deviceCode"]; } set { base["deviceCode"] = value; } }[ConfigurationProperty("fields", IsDefaultCollection =false )]public FiledCollection Fileds { get { return (FiledCollection)this["fields"]; } set { base["fields"] = value; } }}public class FiledCollection : ConfigurationElementCollection{protected override ConfigurationElement CreateNewElement(){return new FieldElement();}protected override object GetElementKey(ConfigurationElement element){FieldElement fieldElement = element as FieldElement;return fieldElement?.FieldName;}//public override ConfigurationElementCollectionType CollectionType//{//    get//    {//        return ConfigurationElementCollectionType.BasicMap;//    }//}public FieldElement this[int index]{get { return (FieldElement)BaseGet(index); }set{if (BaseGet(index) != null){BaseRemoveAt(index);}BaseAdd(index, value);}}public new  string this[string key]{get { return ((FieldElement)base.BaseGet(key)).FieldId; }}}public class FieldElement : ConfigurationElement{/// <summary>/// IsRequired  获取或设置一个值,指示经过修饰的元素属性是否是必需的/// IsKey 如果此属性是该集合中元素的 Key 属性,则为 true;否则为 false。 默认值为 false。/// </summary>[ConfigurationProperty("fieldName", IsRequired = true, IsKey = true)]public string FieldName { get { return (string)base["fieldName"]; } set { base["fieldName"] = value; } }[ConfigurationProperty("fieldId", IsRequired = true)]public string FieldId { get { return (string)base["fieldId"]; } set { base["fieldId"] = value; } }}
 DeviceFieldonfig d = (DeviceFieldonfig)System.Configuration.ConfigurationManager.GetSection("deviceFieldConfig");string content = d.Fileds["BCSP2D"];

http://www.ppmy.cn/news/1458415.html

相关文章

计算机系列之软件工程基础知识

22、软件工程基础知识&#xff08;占8-10分&#xff09; 1、信息系统生命周期 ◆软件工程基本原理:用分阶段的生命周期计划严格管理、坚持进行阶段评审、实现严格的产品控制采用现代程序设计技术、结果应能清楚的审查、开 发小组的人员应少而精、承认不断改进软件工程实践的必…

django和vue开发的前后端分离网站怎么部署到服务器上,django和vue前后端分离网站怎么通过宝塔部署

提示&#xff1a;如果看完全部教程后仍然部署不成功&#xff0c;可以联系作者 一、提前准备 想要把django vue 前后端分离网站部署到服务器上&#xff0c;有一些提前准备的东西 1、备案域名&#xff08;域名必须备案&#xff09; 这里需要解析两个域名&#xff0c;一个前端&…

uni-app 安装 uni-app-fetch 进行接口请求的封装

1、在 uni-app 中通过 uni.request 发起网络请求&#xff0c;在实际的应用中需要结合一些业务场景进行二次封装&#xff0c;比如配置 baseURL、拦截器等&#xff0c; 1、uni-app-fetch 是对 uni.request 的封装&#xff0c;通过 npm 来安装该模块 # 安装 uni-app-fetch 模块 …

(五)JSP教程——response对象

response对象主要用于动态响应客户端请求&#xff08;request&#xff09;&#xff0c;然后将JSP处理后的结果返回给客户端浏览器。JSP容器根据客户端的请求建立一个默认的response对象&#xff0c;然后使用response对象动态地创建Web页面、改变HTTP标头、返回服务器端地状态码…

Element-ui-vue3-前端界面开发-配置-编辑main.js-nodejs基础语法-vue3-html模板语法-vue文件编译

前端配置 1.下载nodejs 18 lts2.配置nodejs和安装vue3.vue调试技巧3.1.debugger3.2.vue devtools4.编辑main.js5.nodejs基础语法5.1.import5.1.1.导入单个模块或组件5.1.2.导入整个模块或库5.1.3.导入默认导出5.1.4.导入 css文件5.1.5.导入模块和组件5.2.export5.2.1.命名导出5…

解决github无法克隆私有仓库,Repository not found问题(2024最新)

一、背景 这个问题出现&#xff0c;是你用了其他主机设备&#xff0c;需要重新clone私有库时&#xff0c;发现一直报找不到仓库&#xff0c;如下报错&#xff1a; remote: Repository not found.二、解决方法 &#xff08;1&#xff09;账号密码方式&#xff08;已不支持&am…

保持学习:数据分析由浅入深

最近在找数据分析的工作&#xff0c;对此先提前加以学习。 来源于&#xff1a;9张图&#xff0c;看懂数据分析如何由浅入深 | 人人都是产品经理 (woshipm.com) 1、一个优秀的数据分析表格可以清楚的对数据变化进行表达&#xff0c;并且从多方位进行思考也会更加有深度。 2、…

Java 线程池之 ThreadPoolExecutor

Java线程池&#xff0c;特别是ThreadPoolExecutor&#xff0c;是构建高性能、可扩展应用程序的基石之一。它不仅关乎效率&#xff0c;还直接关系到资源管理与系统稳定性。想象一下&#xff0c;如果每来一个请求就创建一个新的线程&#xff0c;服务器怕是很快就要举白旗了。而Th…