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

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

private GetSectionInstance ( System.Configuration.SectionInfo config, bool createDefaultInstance ) : ConfigurationSection
config System.Configuration.SectionInfo
createDefaultInstance bool
Результат ConfigurationSection
		internal ConfigurationSection GetSectionInstance (SectionInfo config, bool createDefaultInstance)
		{
			object data = elementData [config];
			ConfigurationSection sec = data as ConfigurationSection;
			if (sec != null || !createDefaultInstance) return sec;
			
			object secObj = config.CreateInstance ();
			sec = secObj as ConfigurationSection;
			if (sec == null) {
				DefaultSection ds = new DefaultSection ();
				ds.SectionHandler = secObj as IConfigurationSectionHandler;
				sec = ds;
			}
			sec.Configuration = this;

			ConfigurationSection parentSection = null;
			if (parent != null) {
				parentSection = parent.GetSectionInstance (config, true);
				sec.SectionInformation.SetParentSection (parentSection);
			}
			sec.SectionInformation.ConfigFilePath = FilePath;

			sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath);
			
			string xml = data as string;
			sec.RawXml = xml;
			sec.Reset (parentSection);

			if (xml != null && xml == data) {
				XmlTextReader r = new ConfigXmlTextReader (new StringReader (xml), FilePath);
				sec.DeserializeSection (r);
				r.Close ();

				if (!String.IsNullOrEmpty (sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty (FilePath))
					sec.DeserializeConfigSource (Path.GetDirectoryName (FilePath));
			}
			
			elementData [config] = sec;
			return sec;
		}
		

Usage Example

Пример #1
0
 public ConfigurationSection this[string name]
 {
     get
     {
         var sec = BaseGet(name) as ConfigurationSection;
         if (sec == null)
         {
             var secData = _group.Sections[name] as SectionInfo;
             if (secData == null)
             {
                 return(null);
             }
             sec = _config.GetSectionInstance(secData, true);
             if (sec == null)
             {
                 return(null);
             }
             lock (LockObject)
             {
                 BaseSet(name, sec);
             }
         }
         return(sec);
     }
 }
All Usage Examples Of System.Configuration.Configuration::GetSectionInstance