WPF程序中App.Config文件的读与写

本文详细介绍了WPF程序中App.Config文件的使用方法,包括基本读写操作、自定义配置节点及复杂操作等内容。

WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就这个部分来做一次系统性的总结。
  
App.Config文件是系统默认的应用程序配置文件,在我们使用后进行编译时会生成“程序集名称+.exe.config”文件,其本质上也是一个XML文件,在我们的应用程序中添加应用程序配置文件后,默认生成下面的内容。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

后面可以根据需要添加我们想要配置的内容,例如我们想要自定义一个section,那么我们首先需要增加一个configSections节点,然后再添加section子节点,在子节点中我们需要添加名称name 类型type等节点信息,具体配置信息如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration> 
 <configSections>
   <section name="eas" type="EAS.ConfigHandler,EAS.MicroKernel"/>
   <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"                           requirePermission="false"/>
  </configSections>
  <eas>
    <objects>
      <object  name="MessageBus" assembly="EAS.MicroKernel" type="EAS.Sockets.Bus.SocketBus" LifestyleType="Singleton">
        <property name="Url" type="string" value="socket.tcp://127.0.0.1:1000/"/>
      </object>
    </objects>
  </eas> 
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
  </entityFramework>
  <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
  <appSettings>   
    <add key="AspNetAddress" value="http://192.168.3.199:8088"/>  
    <add key="ServerDog" value="192.168.3.199:8001"/>
    <add key="DICSCtrl" value="192.168.3.100:4503"/>
    <add key="BGServerDeamon" value="192.168.3.199:5915"/>
    <add key="MySQLServer" value="localhost"/>
    <add key="DataSimulator" value="DataRinse"/>
    <!--当前软件部署的时间-->
    <add key="DeploymentTime" value="20170822"/>
    <add key="UnitWidth" 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BeanGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值