C# 中自定义配置
2024-08-27 09:04:36
微软在ConfigurationManager类里面为我们提供了AppSetting和ConnectionStrings 两个常用配置,
但是有时候我们需要自定的配置,例如
<image left="40" top="250" width="300" height="200" uri="test.png"/>
这样的配置要如何实现呢?
步骤入如下:
1、打开App.config
2、在App.config中添加,下面的<configSection>
<configuration>
<configSections>
<section name="image" type="System.Configuration.SingleTagSectionHandler"/>
</configSections>
3、<configSection>必须是第一个XML节点
4、如果<configSection>以及存在了,就不用加。
5、然后在<configration>下面加入<image>节点
<configuration>
<configSections> <section name="image" type="System.Configuration.SingleTagSectionHandler"/>
</configSections> <image left="40" top="250" width="300" height="200" uri="test.png"/> </entityFramework>
</configuration>
6、然后程序就可以读了!
代码如下
namespace TestFilter
{
class Program
{
static void Main(string[] args)
{ Hashtable remoteDataSource =
(Hashtable)ConfigurationManager.GetSection("image");
string left= (string)remoteDataSource["left"];
string top= (string)remoteDataSource["top"];
string uri = (string)remoteDataSource["uri"];
}
}
}
最新文章
- 第七章 人工智能,7.6 DNN在搜索场景中的应用(作者:仁重)
- HDU 5934 Bomb(炸弹)
- java守护线程的理解
- json_encode详解,转义
- J2EE中你必须了解的13种技术规范
- 如何使用eclipse进行嵌入式Linux的开发
- java18 任务调度
- iOS 9 地图定位崩溃 n: &#39;Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->;fClient)&#39;
- js动画学习(二)
- HDU4325--Flowers--树状数组,离散化
- Appium 解决手势密码 java
- webx request注入单例增强实现
- 使用 WeihanLi.Npoi 操作 CSV
- LeetCode算法题-Number Complement(Java实现-五种解法)
- 深入理解Fabric环境搭建的详细过程
- JumpServer 安装配置
- 我的第二本译作《精通OpenStack》上架啦:前言、目录和样章
- 别人的Linux私房菜(19)认识与分析日志文件
- Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
- WebService学习总结(一)——WebService的相关概念
热门文章
- Nginx配置文件的反向代理
- WXS-运算符
- php str_getcsv解决explode不能解决的问题
- 生命不息,奔跑不止,持之以恒,勇攀高峰——JasonCeng的跑步打卡
- LeetCode 665. 非递减数列(Non-decreasing Array)
- LeetCode 50. Pow(x, n) 12
- OpenCV基于字节指针进行高效像素遍历
- [Visual Studio] - 使用 Fiddler 时,禁止监控 VSHub 请求的方法
- .NET Core IOC AOP
- Java基础笔试练习(六)