zoukankan      html  css  js  c++  java
  • C# 中自定义配置

    微软在ConfigurationManager类里面为我们提供了AppSetting和ConnectionStrings 两个常用配置,

    但是有时候我们需要自定的配置,例如

      <image left="40" top="250" width="300" height="200" uri="test.png"/>

    这样的配置要如何实现呢?

    步骤入如下:

    1、打开App.config

    2、在App.config中添加,下面的<configSection>

    1 <configuration>
    2   <configSections>
    3     <section name="image" type="System.Configuration.SingleTagSectionHandler"/>
    7   </configSections>

    3、<configSection>必须是第一个XML节点

    4、如果<configSection>以及存在了,就不用加。

    5、然后在<configration>下面加入<image>节点

     1 <configuration>
     2   <configSections>
     3 
     4     <section name="image"  type="System.Configuration.SingleTagSectionHandler"/>
     5   </configSections>
     6   
     7  
     8   <image left="40" top="250" width="300" height="200" uri="test.png"/>
     9 
    10 
    11   </entityFramework>
    12 </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"];
            }
        }
    }
  • 相关阅读:
    浅谈线性 Linear
    Github TinyRenderer渲染器课程实践记录
    蓝点无限UWB TDOA 低功耗标签 功耗测试
    UWB DW1000 BP30 测距代码架构
    C语言
    C语言
    张量tensor 和张量分解 tensor decomposition
    Manifold learning流行学习和谱聚类
    机器学习里面的核kernel, 维数灾难
    机器学习评价方法
  • 原文地址:https://www.cnblogs.com/songr/p/9082294.html
Copyright © 2011-2022 走看看