System.Configuration.Configuration.CreateSection C# (CSharp) Метод

CreateSection() приватный Метод

private CreateSection ( System.Configuration.SectionGroupInfo group, string name, ConfigurationSection sec ) : void
group System.Configuration.SectionGroupInfo
name string
sec ConfigurationSection
Результат void
		internal void CreateSection (SectionGroupInfo group, string name, ConfigurationSection sec)
		{
			if (group.HasChild (name))
				throw new ConfigurationException ("Cannot add a ConfigurationSection. A section or section group already exists with the name '" + name + "'");
				
			if (!HasFile && !sec.SectionInformation.AllowLocation)
				throw new ConfigurationErrorsException ("The configuration section <" + name + "> cannot be defined inside a <location> element."); 

			if (!system.Host.IsDefinitionAllowed (configPath, sec.SectionInformation.AllowDefinition, sec.SectionInformation.AllowExeDefinition)) {
				object ctx = sec.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication ? (object) sec.SectionInformation.AllowExeDefinition : (object) sec.SectionInformation.AllowDefinition;
				throw new ConfigurationErrorsException ("The section <" + name + "> can't be defined in this configuration file (the allowed definition context is '" + ctx + "').");
			}

			if (sec.SectionInformation.Type == null)
				sec.SectionInformation.Type = system.Host.GetConfigTypeName (sec.GetType ());

			SectionInfo section = new SectionInfo (name, sec.SectionInformation);
			section.StreamName = streamName;
			section.ConfigHost = system.Host;
			group.AddChild (section);
			elementData [section] = sec;
		}
		

Usage Example

Пример #1
0
 public void Add(string name, ConfigurationSection section)
 {
     config.CreateSection(group, name, section);
 }