gpt4 book ai didi

c# - 如何从 C# 中的 userSettings 部分检索值

转载 作者:行者123 更新时间:2023-11-30 16:07:53 25 4
gpt4 key购买 nike

我有这个配置文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DynamicFormWorker.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<userSettings>
<DynamicFormWorker.Properties.Settings>
<setting name="mandator" serializeAs="String">
<value>$$mandator$$</value>
</setting>
</DynamicFormWorker.Properties.Settings>
</userSettings>
<appSettings>
<add key="log4net.Config" value="log4net.config" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>

现在我想出了如何在 C# 中加载具体的配置文件,但实际上我没有获得强制元素的值。

我正在像这样加载 exe 配置

        configLocation = new ExeConfigurationFileMap();            
configLocation.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App.config");
exeConfig = ConfigurationManager.OpenMappedExeConfiguration(configLocation, ConfigurationUserLevel.None);

但是我如何检索 userSettings 中的 mandator 元素?谢谢

最佳答案

我没有断言这是达到该值的“标准”或“可接受”方式(这似乎太冗长了!)但您可以这样做:

ConfigurationSectionGroup userSettings = config.SectionGroups["userSettings"];
var settingsSection = userSettings.Sections["DynamicFormWorker.Properties.Settings"] as ClientSettingsSection;
string mandator = settingsSection.Settings.Get("mandator").Value.ValueXml.InnerText;

关于c# - 如何从 C# 中的 userSettings 部分检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30172638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com