【问题标题】:.NET Type loadable from App.Config.NET 类型可从 App.Config 加载
【发布时间】:2009-03-27 04:36:10
【问题描述】:

如何设计一种类型,以与 SMTPClient 类或 TraceListener 相同的方式从 App.Config 文件加载其属性?这样做时我应该遵循什么标准?

【问题讨论】:

    标签: configuration .net-2.0 app-config


    【解决方案1】:

    查看ConfigurationSection 类和ConfigurationElement

    这是一篇不错的教程文章 http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

    这是从 machine.config 中截取的 system.net 配置组

    <sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="authenticationModules" type="System.Net.Configuration.AuthenticationModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="connectionManagement" type="System.Net.Configuration.ConnectionManagementSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <sectionGroup name="mailSettings" type="System.Net.Configuration.MailSettingsSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="smtp" type="System.Net.Configuration.SmtpSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </sectionGroup>
      <section name="requestCaching" type="System.Net.Configuration.RequestCachingSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="settings" type="System.Net.Configuration.SettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <section name="webRequestModules" type="System.Net.Configuration.WebRequestModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </sectionGroup>
    

    【讨论】:

      猜你喜欢
      • 2017-04-07
      • 1970-01-01
      • 2013-06-05
      • 2018-05-24
      • 2019-09-28
      • 2023-01-22
      • 2015-10-24
      • 2013-05-02
      • 2013-03-24
      相关资源
      最近更新 更多