在开发过程中,无论如何都需要配置文件。 为了便于获取配置文件的参数数据,我们根据自己的使用习惯封装了配置文件参数的读取。 首先贴上配置文件
来看一下. net 6中配置参数的读取方法,首先注入IConfiguration界面

[自动]公共配置配置{ get; set; //配置文件参数的获取方法1
boolisprintlog=configuration.getvalue ( is printlog ); string name3=configuration.getvalue ( student:name ); //轮廓参数获取方法2
string name=configuration.getsection ( ' student ' ) ['name']; string name2=configuration [ ' student:name ' ]; studentconfigurationstu2=configuration.getsection ( ' student ' ).get ); list strlist=configuration.getsection ( ' strlist ' ).get ); list book list=configuration.getsection ( student:books ).get ); 其实使用起来很方便了。 我自己进行包的读取方法
//读取对象studentconfigurationstu3=configuration.gett (; //集合list class list=configuration.getlistt (; 共享封装步骤。 1 .定义配置参数标签的特性
[ attribute usage ( attribute targets.class ) ] publicclassconfigtagattribute:attribute ) publicstringconfigkey{get; set; } publicconfigtagattribute ( string key ) { ConfigKey=key; }2.根据配置文件参数模板定义目标模型
//ConfigTag设置配置文件中的参数级别。 参数级别按[configtag('student:books )//config tag ( ' student ' ) ]publicclassstudentconnt )的方式进行拼接使用; } public int age { get; set; }公共列表books { get; set; } public ClassModel classInfo { get; set; }3.定义I configuration的扩展方法,扩展获取对象的方法和获取对象集合的方法
publicstaticclassconfigurationextension { publicstatictgett ( thisiconfigurationconfiguration ) tt=default; typetype=typeof(t; configtagattributeconfigtagattribute=type.getcustomattribute (; if ( configtagattribute==null ( { returnt; } stringconfigpath=configtagattribute.config key; 配置路径==空| |配置路径==' ' ( { returnt; } t=configuration.getsection ( config path ).get ); 返回t; } publicstaticlistgetlistt ( thisiconfigurationconfiguration ) { List list=null; typetype=typeof(t; configtagattributeconfigtagattribute=type.getcustomattribute (; if ( configtagattribute==null ( { return list; } stringconfigpath=configtagattribute.config key; 配置路径==空| |配置路径==' ' ( { return list; } list=configuration.getsection ( config path ).get ); 返回列表; }4.获取基础类型( int、string、bool等)的方法没有封装,本机可以获取的使用位置可以注入IConfiguration,然后调用扩展方法获取
王者荣耀和小兵互动是七周年的一个活动玩法,想要完成和小兵互动领取加星卡,那么就要按照下面主编提供的方法去
文章导读:现在哪个仙侠手游好?主编今天来给大家推荐一些治愈唯美的手游吧,现在哪个仙侠手游好的推荐,相信有很对
我的世界冰火传说沙蚁螫针剑怎么做很多玩家不知道,冰火传说有很多非常好用的道具武器,沙蚁螫针剑对于其他生物
在《三角战略(TRIANGLE STRATEGY)》中,安娜的定位是刺客/切后排/控制/残局收割,非常强悍的女刺客,可以在单挑敌人
在《三角战略(TRIANGLE STRATEGY)》中,强盗头子的定位是战士/坦克/前排/盗贼,特色偷道具,机动中规中矩,数值方面还
在《三角战略(TRIANGLE STRATEGY)》中,王女-科迪莉亚是第15章选择帮助王子清除残党,特色是拥有诸多强大的恢复技
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19
时间:2022-12-19