まず、構成がクラスにマッピングされました
1、構成が増加します
<configSections> <セクション名= " appConfiguration "タイプ= " OilDigital.CGGL.AppConfig.AppConfigurationHandler、OilDigital.CGGL.AppConfig、カルチャニュートラル、PublicKeyToken = = null " /> </ configSections> <appConfiguration> < EnterPriseName > 中石油 </ EnterPriseName > </ appConfiguration>
2、クラス
パブリック クラスAppConfiguration:System.Configuration.ConfigurationSection { パブリックAppConfiguration() { } /// <要約> /// 企业名称 /// </要約> [ConfigurationProperty(" EnterPriseName "、のDefaultValue = " 工程建设公司" )] パブリック 文字列 EnterPriseName { 取得 { 戻り(文字列)この [ " EnterPriseName " ]。} セット { この [ " EnterPriseName " ] = 値。} } }
使用して3、
AppConfigurationコンフィグ=(AppConfiguration)System.Configuration.ConfigurationManager.GetSection(" appConfiguration ")。