Jel*_*lsa 2 c# configurationmanager web-config-transform
我尝试从一个小节中获取所有属性,但该节有很多小节并且应用程序无法识别,我该怎么办?这是我的网络配置:
<configSections>
<section name="Seccion" type="ManejoConfiguracion.SeccionConfig,ManejoConfiguracion"/>
</configSections>
<Seccion>
<BD>
<add key="name" value="dbKey" />
<add key="user" value="userBD" />
<add key="pass" value="123BD" />
</BD>
<ReportingService>
<add key="name" value="Reporting" />
<add key="user" value="userReport" />
</ReportingService>
</Seccion>
</configuration>
Run Code Online (Sandbox Code Playgroud)
呸! 忘记那些疯狂的配置对象。使用 Linq to XML 就可以了:
var seccion =
XDocument.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
.Root.Element("Seccion");
// Now Linq to XML until your heart's content!
var user = (string)seccion.Element("BD").Elements("add")
.Where(x => (string)x.Attribute("key") == "user")
.Single().Attribute("value");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2202 次 |
| 最近记录: |