本文整理汇总了C#中System.Configuration.Configuration.GetSection方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.GetSection方法的具体用法?C# Configuration.GetSection怎么用?C# Configuration.GetSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.GetSection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigReader
public ConfigReader()
{
config__ = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
backupConfigHandler__ = (BackupConfigHandler)config__.GetSection("BackupConfig");
editorCompilerConfigHandler__ = (EditorCompilerConfigHandler)config__.GetSection("EditorCompilerConfig");
preferenceConfigHandler__ = (PreferenceConfigHandler)config__.GetSection("PreferenceConfig");
}
示例2: ReadToolsetConfigurationSection
internal static ToolsetConfigurationSection ReadToolsetConfigurationSection(Configuration configuration)
{
ToolsetConfigurationSection configurationSection = null;
// This will be null if the application config file does not have the following section
// definition for the msbuildToolsets section as the first child element.
// <configSections>
// <section name=""msbuildToolsets"" type=""Microsoft.Build.Evaluation.ToolsetConfigurationSection, Microsoft.Build"" />
// </configSections>";
// Note that the application config file may or may not contain an msbuildToolsets element.
// For example:
// If section definition is present and section is not present, this value is not null
// If section definition is not present and section is also not present, this value is null
// If the section definition is not present and section is present, then this value is null
if (null != configuration)
{
ConfigurationSection msbuildSection = configuration.GetSection("msbuildToolsets");
configurationSection = msbuildSection as ToolsetConfigurationSection;
if (configurationSection == null && msbuildSection != null) // we found msbuildToolsets but the wrong type of handler
{
if (String.IsNullOrEmpty(msbuildSection.SectionInformation.Type) ||
msbuildSection.SectionInformation.Type.IndexOf("Microsoft.Build", StringComparison.OrdinalIgnoreCase) >= 0)
{
// Set the configuration type handler to the current ToolsetConfigurationSection type
msbuildSection.SectionInformation.Type = typeof(ToolsetConfigurationSection).AssemblyQualifiedName;
try
{
// fabricate a temporary config file with the correct section handler type in it
string tempFileName = FileUtilities.GetTemporaryFile();
// Save the modified config
configuration.SaveAs(tempFileName + ".config");
// Open the configuration again, the new type for the section handler will do its stuff
// Note that the OpenExeConfiguraion call uses the config filename *without* the .config
// extension
configuration = ConfigurationManager.OpenExeConfiguration(tempFileName);
// Get the toolset information from the section using our real handler
configurationSection = configuration.GetSection("msbuildToolsets") as ToolsetConfigurationSection;
File.Delete(tempFileName + ".config");
File.Delete(tempFileName);
}
catch (Exception ex)
{
if (ExceptionHandling.NotExpectedException(ex))
{
throw;
}
}
}
}
}
return configurationSection;
}
示例3: ApplicationSettings
public ApplicationSettings()
{
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
General = (GeneralSettings)config.GetSection("general");
SerialPorts = (SerialPortSettings)config.GetSection("serialPorts");
Plugins = (PluginSettings)config.GetSection("plugin");
ConnectionStrings = config.ConnectionStrings.ConnectionStrings;
}
示例4: Init
private static void Init()
{
_config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
// Map the roaming configuration file. This enables the application to access the configuration file using the
// System.Configuration.Configuration class
//var configFileMap = new ExeConfigurationFileMap {ExeConfigFilename = roamingConfig.FilePath};
// Get the mapped configuration file.
//_config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
//Get the configuration section or create it
_dialerConfig = (PlacetelDialerConfig) _config.GetSection(SectionName);
if (_dialerConfig == null)
{
_dialerConfig = new PlacetelDialerConfig();
_dialerConfig.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
_dialerConfig.SectionInformation.AllowOverride = true;
_config.Sections.Add(SectionName, _dialerConfig);
//Save the initial state
_config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(SectionName);
}
}
示例5: TreeTabConfig
/// <summary>
/// Loads the config file
/// </summary>
public TreeTabConfig()
{
try
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
System.Uri uri = new Uri(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location));
fileMap.ExeConfigFilename = Path.Combine(uri.LocalPath, CONFIG_FILENAME);
config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
if (config.HasFile)
{
ConfigurationSection cs = config.GetSection(CONTEXT_MENU_ICONS_SECTION);
if (cs != null)
{
XmlDocument xmlConf = new XmlDocument();
xmlConf.LoadXml(cs.SectionInformation.GetRawXml());
xmlContextMenuIcons = (XmlElement)xmlConf.FirstChild;
this.isCorrectlyLoaded = true;
}
}
}
catch
{
this.isCorrectlyLoaded = false;
}
}
示例6: GetConfiguration
/// <summary>
/// This method will retrieve the configuration settings.
/// </summary>
private void GetConfiguration()
{
try
{
m_config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
if (m_config.Sections["TracePreferences"] == null)
{
m_settings = new TracePreferences();
m_config.Sections.Add("TracePreferences", m_settings);
m_config.Save(ConfigurationSaveMode.Full);
}
else
m_settings = (TracePreferences)m_config.GetSection("TracePreferences");
}
catch (InvalidCastException e)
{
System.Diagnostics.Trace.WriteLine("Preference Error - " + e.Message, "MainForm.GetConfiguration");
MessageBoxOptions options = 0;
MessageBox.Show(Properties.Resources.PREF_NOTLOADED, Properties.Resources.PREF_CAPTION,
MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, options);
m_settings = new TracePreferences();
}
catch (ArgumentException e)
{
System.Diagnostics.Trace.WriteLine("Argument Error - " + e.Message, "MainForm.GetConfiguration");
throw;
}
catch (ConfigurationErrorsException e)
{
System.Diagnostics.Trace.WriteLine("Configuration Error - " + e.Message, "MainForm.GetConfiguration");
throw;
}
}
示例7: GetConfigSection
private ClientSettingsSection GetConfigSection(Configuration config, string sectionName, bool declare) {
string fullSectionName = UserSettingsGroupPrefix + sectionName;
ClientSettingsSection section = null;
if (config != null) {
section = config.GetSection(fullSectionName) as ClientSettingsSection;
if (section == null && declare) {
// Looks like the section isn't declared - let's declare it and try again.
DeclareSection(config, sectionName);
section = config.GetSection(fullSectionName) as ClientSettingsSection;
}
}
return section;
}
示例8: btnSubmit_Click
protected void btnSubmit_Click(object sender, EventArgs e)
{
Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
//操作appSettings
AppSettingsSection appseting = (AppSettingsSection)Configuration.GetSection("appSettings"); //修改设置
try
{
appseting.Settings["txtiosapplink"].Value = this.txtiosapplink.Text;
}
catch (Exception)
{
appseting.Settings.Add("txtiosapplink", this.txtiosapplink.Text);
}
try
{
appseting.Settings["txtapklink"].Value = this.txtapklink.Text;
}
catch (Exception)
{
appseting.Settings.Add("txtapklink", this.txtapklink.Text);
}
Configuration.Save();
}
示例9: AddModule
// https://msdn.microsoft.com/en-us/library/tkwek5a4%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
// Example Configuration Code for an HTTP Module:
public static void AddModule(Configuration config, string moduleName, string moduleClass)
{
HttpModulesSection section =
(HttpModulesSection)config.GetSection("system.web/httpModules");
// Create a new module action object.
HttpModuleAction moduleAction = new HttpModuleAction(
moduleName, moduleClass);
// "RequestTimeIntervalModule", "Samples.Aspnet.HttpModuleExamples.RequestTimeIntervalModule");
// Look for an existing configuration for this module.
int indexOfModule = section.Modules.IndexOf(moduleAction);
if (-1 != indexOfModule)
{
// Console.WriteLine("RequestTimeIntervalModule module is already configured at index {0}", indexOfModule);
}
else
{
section.Modules.Add(moduleAction);
if (!section.SectionInformation.IsLocked)
{
config.Save();
// Console.WriteLine("RequestTimeIntervalModule module configured.");
}
}
}
示例10: OptionsForm
private OptionsForm(bool local)
{
InitializeComponent();
// Copy the Bootstrap.exe file to New.exe,
// so that the configuration file will load properly
string currentDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string sandboxDir = Path.Combine(currentDir, "Sandbox");
if (!File.Exists(Path.Combine(sandboxDir, "New.exe")))
{
File.Copy(
Path.Combine(sandboxDir, "Bootstrap.exe"),
Path.Combine(sandboxDir, "New.exe")
);
}
string filename = local ? "New.exe" : "Bootstrap.exe";
string filepath = Path.Combine(sandboxDir, filename);
_Configuration = ConfigurationManager.OpenExeConfiguration(filepath);
// Get the DDay.Update configuration section
_Cfg = _Configuration.GetSection("DDay.Update") as DDayUpdateConfigurationSection;
// Set the default setting on which application folder to use.
cbAppFolder.SelectedIndex = 0;
SetValuesFromConfig();
if (!local)
_Configuration.SaveAs(Path.Combine(sandboxDir, "New.exe.config"));
}
示例11: AppConfig
/// <summary>
/// Initializes a new instance of AppConfig based on supplied configuration
/// </summary>
/// <param name="configuration">Configuration to load settings from</param>
public AppConfig(Configuration configuration)
: this(
configuration.ConnectionStrings.ConnectionStrings,
configuration.AppSettings.Settings,
(EntityFrameworkSection)configuration.GetSection(EFSectionName))
{
//Contract.Requires(configuration != null);
}
示例12: AppConfig
/// <summary>
/// Initializes a new instance of AppConfig based on supplied configuration
/// </summary>
/// <param name="configuration"> Configuration to load settings from </param>
public AppConfig(Configuration configuration)
: this(
configuration.ConnectionStrings.ConnectionStrings,
configuration.AppSettings.Settings,
(EntityFrameworkSection)configuration.GetSection(EFSectionName))
{
DebugCheck.NotNull(configuration);
}
示例13: GetFormsAuthConfig
private AuthenticationSection GetFormsAuthConfig(out Configuration webConfig)
{
string root = this.Request.ApplicationPath;
webConfig = WebConfigurationManager.OpenWebConfiguration(root);
AuthenticationSection authenticationSection = (AuthenticationSection)webConfig.GetSection("system.web/authentication");
return authenticationSection;
}
示例14: OptionsViewModel
public OptionsViewModel()
{
_configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
_configSection = (BlackJackSection)_configuration.GetSection("blackJack");
_deckFile = _configSection.DeckFile;
_backFile = _configSection.BackFile;
_initialPlayerMoney = _configSection.InitialPlayerMoney;
_initialDealerMoney = _configSection.InitialDealerMoney;
}
示例15: OpenConfigurationFile
private void OpenConfigurationFile()
{
_Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
string configurationName = "GlobalConfiguration";
_GlobalConfiguration = new GlobalConfiguration();
_GlobalConfiguration.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
CreateConfigurationSection(configurationName, _GlobalConfiguration);
_GlobalConfiguration = (GlobalConfiguration)_Configuration.GetSection(configurationName);
configurationName = "TrackEditorConfiguration";
_TrackEditorConfiguration = new Core.Globals.TrackEditorConfiguration();
_TrackEditorConfiguration.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
CreateConfigurationSection(configurationName, _TrackEditorConfiguration);
_TrackEditorConfiguration = (TrackEditorConfiguration)_Configuration.GetSection(configurationName);
}