當前位置: 首頁>>代碼示例>>C#>>正文


C# Configuration.ConfigurationSection類代碼示例

本文整理匯總了C#中System.Configuration.ConfigurationSection的典型用法代碼示例。如果您正苦於以下問題:C# ConfigurationSection類的具體用法?C# ConfigurationSection怎麽用?C# ConfigurationSection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConfigurationSection類屬於System.Configuration命名空間,在下文中一共展示了ConfigurationSection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Save

 public static void Save(ConfigurationSection configSection)
 {
     System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     configuration.Sections.Remove(configSection.SectionInformation.Name);
     configuration.Sections.Add(configSection.SectionInformation.Name, configSection);
     configuration.Save();
 }
開發者ID:karl-barkmann,項目名稱:LeenLeen,代碼行數:7,代碼來源:ConfigurationHelper.cs

示例2: DoCheckGetSection

        /// <summary>
        /// Checks whether the result of a call to <see cref="IConfigurationSource.GetSection(string)"/> should be deferred to a subordinate source.<br/>
        /// If the call should be deferred, returns the <see cref="ConfigurationSection"/> intance from the approriate source.<br/>
        /// If the call should not be deferred returns <paramref name="configurationSection"/>.
        /// </summary>
        /// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
        /// <param name="configurationSection">The section that was retrieved from configuration.</param>
        /// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
        /// <seealso cref="IConfigurationSource.GetSection(string)"/>
        /// <exception cref="ConfigurationSourceErrorsException">Thrown if a section does not exist in a registered source.</exception>
        protected override ConfigurationSection DoCheckGetSection(string sectionName, ConfigurationSection configurationSection)
        {
            string sourceNameForSection;
            if (!sectionRedirectTable.TryGetValue(sectionName, out sourceNameForSection))
            {
                return configurationSection;
            }

            //if no source is specified we can return.
            if (string.IsNullOrEmpty(sourceNameForSection))
            {
                return configurationSection;
            }

            IConfigurationSource subordinateSource = GetSubordinateSource(sourceNameForSection);

            EnsurePropagatingSectionChangeEvents(sourceNameForSection, sectionName);

            var section = subordinateSource.GetSection(sectionName);

            if (section == null)
                throw new ConfigurationSourceErrorsException(
                    string.Format(CultureInfo.CurrentCulture,
                    Resources.ExceptionRedirectedConfigurationSectionNotFound,
                    sectionName,
                    sourceNameForSection));

            return section;
        }
開發者ID:modulexcite,項目名稱:Transformalize,代碼行數:39,代碼來源:CompositeConfigurationSourceHandler.cs

示例3: OverrideWithGroupPolicies

        public override bool OverrideWithGroupPolicies(ConfigurationSection configurationObject,
            bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey)
        {
            called = true;
            this.configurationObject = configurationObject;
            this.readGroupPolicies = readGroupPolicies;
            this.machineKey = machineKey;
            this.userKey = userKey;

            IRegistryKey policyKey = GetPolicyKey(machineKey, userKey);
            if (policyKey != null)
            {
                if (!policyKey.GetBoolValue(PolicyValueName).Value)
                {
                    return false;
                }

                TestsConfigurationSection section = configurationObject as TestsConfigurationSection;
                if (section != null)
                {
                    try
                    {
                        section.Value = policyKey.GetStringValue(ValuePropertyName);
                    }
                    catch (RegistryAccessException)
                    { }
                }
            }

            return true;
        }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:31,代碼來源:MockConfigurationSectionManageabilityProviderBase.cs

示例4: Add

        /// <summary>
        /// Adds a <see cref="ConfigurationSection"/> to the configuration source location specified by 
        /// <paramref name="saveParameter"/> and saves the configuration source.
        /// </summary>
        /// <remarks>
        /// If a configuration section with the specified name already exists in the location specified by 
        /// <paramref name="saveParameter"/> it will be replaced.
        /// </remarks>
        /// <param name="saveParameter">The <see cref="IConfigurationParameter"/> that represents the location where 
        /// to save the updated configuration. Must be an instance of <see cref="FileConfigurationParameter"/>.</param>
        /// <param name="sectionName">The name by which the <paramref name="configurationSection"/> should be added.</param>
        /// <param name="configurationSection">The configuration section to add.</param>
        public void Add(IConfigurationParameter saveParameter, string sectionName, ConfigurationSection configurationSection)
        {
            FileConfigurationParameter parameter = saveParameter as FileConfigurationParameter;
            if (null == parameter) throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionUnexpectedType, typeof(FileConfigurationParameter).Name), "saveParameter");

            Save(parameter.FileName, sectionName, configurationSection);
        }
開發者ID:bnantz,項目名稱:NCS-V2-0,代碼行數:19,代碼來源:FileConfigurationSource.cs

示例5: GetSectionRelativeFile

		/// <summary>
		/// 得到Section的相關文件
		/// </summary>
		/// <param name="config"></param>
		/// <param name="section"></param>
		/// <returns></returns>
		public static string GetSectionRelativeFile(this System.Configuration.Configuration config, ConfigurationSection section)
		{
			string result = string.Empty;

			if (config != null && section != null)
			{
				string configSource = section.SectionInformation.ConfigSource;

				if (configSource.IsNullOrEmpty())
				{
					ConfigurationSection sectionInConfig = GetSectionRecursively(config, section.SectionInformation.SectionName);

					if (sectionInConfig != null)
						configSource = sectionInConfig.SectionInformation.ConfigSource;
				}

				if (configSource.IsNotEmpty() && config.FilePath.IsNotEmpty())
				{
					string configDir = Path.GetDirectoryName(config.FilePath);

					result = Path.Combine(configDir, configSource);
				}
			}

			return result;
		}
開發者ID:jerryshi2007,項目名稱:AK47Source,代碼行數:32,代碼來源:ConfigurationExtension.cs

示例6: Add

 public void Add(string sectionName, ConfigurationSection configurationSection)
 {
     if (CompositeConfigurationSource.CheckAddSection(sectionName, configurationSection)) return;
     
     contents.Add(sectionName, configurationSection);
     
 }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:7,代碼來源:TestConfigurationSource.cs

示例7: OpenCore

		/// <summary>
		/// Opens the security settings configuration section, builds the design time nodes and adds them to the application node.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		/// <param name="rootNode">The root node of the application.</param>
		/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
		protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
		{
			if (null != section)
            {
				rootNode.AddNode(new SecuritySettingsNodeBuilder(serviceProvider, (SecuritySettings)section).Build());
			}
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:13,代碼來源:SecurityConfigurationDesignManager.cs

示例8: CheckGetSection

        /// <summary>
        /// Checks whether a call to <see cref="IConfigurationSource.GetSection(string)"/> should be extended.<br/>
        /// If the call should be extended performs the extended behavior and returns the modified <see cref="ConfigurationSection"/> intance.<br/>
        /// If the call should not be extended returns <paramref name="configurationSection"/>.
        /// </summary>
        /// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
        /// <param name="configurationSection">The section that was retrieved from configuration.</param>
        /// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
        /// <seealso cref="IConfigurationSource.GetSection(string)"/>
        public ConfigurationSection CheckGetSection(string sectionName, ConfigurationSection configurationSection)
        {
            //design time managers occasionally call with sectionName == "".
            //this should be fixed in designtime managers
            if (string.IsNullOrEmpty(sectionName)) //   throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "sectionName");
            {
                return configurationSection;
            }

            //if we are already loading we should return.
            if (RecursionLock.InsideHandlerOperation)
            {
                return configurationSection;
            }

            //this is a section we depend on internally
            if (sectionName == ConfigurationSourceSection.SectionName)
            {
                return configurationSection;
            }

            lock (LockObject)
            {
                using (new RecursionLock())
                {
                    EnsureInitialized();

                    return DoCheckGetSection(sectionName, configurationSection);
                }
            }
        }
開發者ID:HondaBey,項目名稱:EnterpriseLibrary6,代碼行數:40,代碼來源:ConfigurationSourceHandler.cs

示例9: SaveSection

        private static void SaveSection(System.Configuration.Configuration config, ConfigurationSection section)
        {
            // Save the section.
            section.SectionInformation.ForceSave = true;

            config.Save(ConfigurationSaveMode.Full);
        }
開發者ID:alienwaredream,項目名稱:toolsdotnet,代碼行數:7,代碼來源:ProtectConfigSection.cs

示例10: Apply

        /// <inheritdoc />
        public void Apply(ConfigurationSection section)
        {
            Ensure.ArgumentNotNull(section, "section");
            Ensure.ArgumentTypeAssignableFrom(typeof(CustomConfigurationSection), section.GetType(), "section");

            this.section = (CustomConfigurationSection)section;
        }
開發者ID:WenningQiu,項目名稱:appccelerate,代碼行數:8,代碼來源:ExtensionWithCustomConfigurationSection.cs

示例11: Clone

        ///<summary>
        /// Clones a <see cref="ConfigurationSection"/>
        ///</summary>
        ///<param name="section">The <see cref="ConfigurationSection"/> to clone.</param>
        ///<returns>A new, cloned <see cref="ConfigurationSection"/>.</returns>
        public ConfigurationSection Clone(ConfigurationSection section)
        {
            if (section == null) throw new ArgumentNullException("section");

            var clonedSection = (ConfigurationSection)Activator.CreateInstance(section.GetType());
            return (ConfigurationSection)CloneElement(section, clonedSection);
        }
開發者ID:HondaBey,項目名稱:EnterpriseLibrary6,代碼行數:12,代碼來源:ConfigurationSectionCloner.cs

示例12: OpenCore

 /// <summary>
 /// Opens the instrumenation section, builds the design time nodes and adds them to the application node.
 /// </summary>
 /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
 /// <param name="rootNode">The root node of the application.</param>
 /// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
 protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
 {
     if (null != section)
     {
         rootNode.AddNode(new InstrumentationNode((InstrumentationConfigurationSection)section));
     }
 }
開發者ID:bnantz,項目名稱:NCS-V2-0,代碼行數:13,代碼來源:InstrumentationConfigurationDesignManager.cs

示例13: Add

        // Add a new section to the collection. This will result in a new declaration and definition.
        // It is an error if the section already exists.
        public void Add(string name, ConfigurationSection section)
        {
            VerifyIsAttachedToConfigRecord();

            _configRecord.AddConfigurationSection(_configSectionGroup.SectionGroupName, name, section);
            BaseAdd(name, name);
        }
開發者ID:chcosta,項目名稱:corefx,代碼行數:9,代碼來源:ConfigurationSectionCollection.cs

示例14: PropertyFilter

        /// <summary>
        /// Set Property Filters constructor via ConfigurationSection from configuration file
        /// </summary>
        /// <param name="section">ConfigurationSection from configuration file</param>
        public PropertyFilter(ConfigurationSection section) : this()
        {
            //initialize fields
            if (section != null)
            {
                foreach (KeyValueConfigurationElement keyVal in ((AppSettingsSection)section).Settings)
                {
                    if (!string.IsNullOrEmpty(keyVal.Value))
                    {
                        switch (keyVal.Key.ToUpper())
                        {
                            case "EQUALTO":
                                EqualTo.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
                                break;
                            case "STARTWITH":
                                StartWith.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
                                break;
                            case "CONTAIN":
                                Contain.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
                                break;
                            case "PROPERTYSETSEQUALTO":
                                PropertySetsEqualTo.AddRange(keyVal.Value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(s => s.ToUpper()));
                                break;
                            default:
#if DEBUG
                                Debug.WriteLine(string.Format("Invalid Key - {0}", keyVal.Key.ToUpper()));
#endif
                                break;
                        }
                    }
                }
            }
        }
開發者ID:McLeanBH,項目名稱:XbimExchange,代碼行數:37,代碼來源:PropertyFilter.cs

示例15: OpenCore

 /// <summary>
 /// Opens the oracle connection configuration section, builds the design time nodes and adds them to the application node.
 /// </summary>
 /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
 /// <param name="rootNode">The root node of the application.</param>
 /// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
 protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
 {
     if (null != section)
     {
         OracleConnectionNodeBuilder builder = new OracleConnectionNodeBuilder(serviceProvider, (OracleConnectionSettings)section);
         builder.Build();
     }
 }
開發者ID:bnantz,項目名稱:NCS-V2-0,代碼行數:14,代碼來源:OracleConnectionConfigurationDesignManager.cs


注:本文中的System.Configuration.ConfigurationSection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。