当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.GetSection方法代码示例

本文整理汇总了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");
 }
开发者ID:daxnet,项目名称:guluwin,代码行数:7,代码来源:ConfigReader.cs

示例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;
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:59,代码来源:ToolsetElement.cs

示例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;
 }
开发者ID:sandalkuilang,项目名称:texto,代码行数:8,代码来源:ApplicationSettings.cs

示例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);
            }
        }
开发者ID:hydr,项目名称:PlacetelDialer,代码行数:26,代码来源:Program.cs

示例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;
     }
 }
开发者ID:HydAu,项目名称:PowershellUISamples,代码行数:28,代码来源:TreeTabConfig.cs

示例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;
     }
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:36,代码来源:StartupSettings.cs

示例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;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:16,代码来源:ClientSettingsStore.cs

示例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();
        }
开发者ID:lijiajin1987,项目名称:OfficialWebsite,代码行数:25,代码来源:Home.aspx.cs

示例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.");
                }
            }
        }
开发者ID:akrisiun,项目名称:git-dot-aspx,代码行数:29,代码来源:RoutingModule.cs

示例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"));
        }
开发者ID:jltrem,项目名称:DDay.Update,代码行数:32,代码来源:OptionsForm.cs

示例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);
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:AppConfig.cs

示例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);
 }
开发者ID:christiandpena,项目名称:entityframework,代码行数:12,代码来源:AppConfig.cs

示例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;
        }
开发者ID:Dashboard-X,项目名称:MP3-MusicPlayer-Install-Configure,代码行数:8,代码来源:Login.aspx.cs

示例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;
 }
开发者ID:yakimovim,项目名称:Blackjack,代码行数:9,代码来源:OptionsViewModel.cs

示例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);
               
        }
开发者ID:chinnisuraj1984,项目名称:navigational,代码行数:18,代码来源:Configuration.cs


注:本文中的System.Configuration.Configuration.GetSection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。