-
大小: 82KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-18
- 語言: 其他
- 標簽: app.config??C#??
資源簡介
關于在開發中一個項目中多個app.config共用的問題。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Configuration;
using?System.IO;
using?System.xml;
namespace?FounctionDll
{
????public?class?FounctionClass
????{
????????///?
????????///?這種用法,如果多個dll的配置重名就沒法用了
????????///?
????????///?
????????public?static?string?ShowConfig()
????????{
????????????string?config?=?ConfigurationManager.AppSettings[“key1“];
????????????config?=?string.IsNullOrEmpty(config)???“空字符串“?:?config;
????????????return?config;
????????}
????????///?
????????///?如果是其他dll下的配置這樣用會好一些
????????///?
????????///?
????????public?static?string?ShowOwnerConfig()
????????{
????????????string?file?=?AppDomain.CurrentDomain.baseDirectory?+?@“App1.config“;
????????????string?mconfig?=?GetAttributeValue(file?“key3“);
????????????mconfig?=?string.IsNullOrEmpty(mconfig)???“空字符串“?:?mconfig;
????????????return?mconfig;
????????}
????????public?static?string?GetTestConfig()
????????{
????????????string?config?=?ConfigurationManager.AppSettings[“key1“];
????????????config?=?string.IsNullOrEmpty(config)???“空字符串“?:?config;
????????????return?config;
????????}
????????///?
????????///?獲取配置文件的屬性
????????///?
????????private?static?string?GetAttributeValue(string?file?string?key)
????????{
????????????string?value?=?string.Empty;
????????????try
????????????{
????????????????if?(File.Exists(file))
????????????????{
????????????????????xmlDocument?xml?=?new?xmlDocument();
????????????????????xml.Load(file);
????????????????????xmlNode?xNode?=?xml.SelectSingleNode(“//appSettings“);
????????????????????xmlElement?element?=?(xmlElement)xNode.SelectSingleNode(“//add[@key=‘“?+?key?+?“‘]“);
????????????????????value?=?element.GetAttribute(“value“).ToString();
????????????????}
????????????}
????????????catch?{?}
????????????return?value;
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????162??2013-01-16?15:32??FounctionDll\App.config
?????文件????????165??2013-01-16?15:38??FounctionDll\App1.config
?????文件????????162??2013-01-16?15:32??FounctionDll\bin\Debug\App.config
?????文件????????165??2013-01-16?15:38??FounctionDll\bin\Debug\App1.config
?????文件???????5120??2013-01-17?15:18??FounctionDll\bin\Debug\FounctionDll.dll
?????文件????????162??2013-01-16?15:32??FounctionDll\bin\Debug\FounctionDll.dll.config
?????文件??????13824??2013-01-17?15:18??FounctionDll\bin\Debug\FounctionDll.pdb
?????文件???????2132??2013-01-17?15:11??FounctionDll\FounctionClass.cs
?????文件???????2616??2013-01-16?17:19??FounctionDll\FounctionDll.csproj
?????文件???????5859??2013-01-17?15:25??FounctionDll\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????610??2013-01-16?17:19??FounctionDll\obj\Debug\FounctionDll.csproj.FileListAbsolute.txt
?????文件???????5120??2013-01-17?15:18??FounctionDll\obj\Debug\FounctionDll.dll
?????文件??????13824??2013-01-17?15:18??FounctionDll\obj\Debug\FounctionDll.pdb
?????文件???????1356??2013-01-16?15:24??FounctionDll\Properties\AssemblyInfo.cs
?????文件???????4608??2013-01-17?15:18??li
?????文件????????217??2013-01-17?15:14??li
?????文件??????11776??2013-01-17?15:18??li
?????文件???????2507??2013-01-17?15:18??li
?????文件????????606??2013-01-17?15:18??li
?????文件???????5804??2013-01-17?15:25??li
?????文件????????515??2013-01-17?15:18??li
?????文件???????4608??2013-01-17?15:18??li
?????文件??????11776??2013-01-17?15:18??li
?????文件???????1364??2013-01-17?15:15??li
?????文件????????217??2013-01-17?15:14??TestAppConfig\App.config
?????文件????????324??2013-01-16?15:19??TestAppConfig\App.xaml
?????文件????????309??2013-01-16?15:19??TestAppConfig\App.xaml.cs
?????文件????????217??2013-01-17?15:14??TestAppConfig\bin\Debug\App.config
?????文件????????165??2013-01-16?15:38??TestAppConfig\bin\Debug\App1.config
?????文件???????5120??2013-01-17?15:18??TestAppConfig\bin\Debug\FounctionDll.dll
............此處省略65個文件信息
- 上一篇:簡單代碼解釋器
- 下一篇:常見的抽獎-根據指定概率抽獎改進
評論
共有 條評論