System.Configuration.ConfigurationSection.DeserializeConfigSource C# (CSharp) Method

DeserializeConfigSource() private method

private DeserializeConfigSource ( string basePath ) : void
basePath string
return void
		internal void DeserializeConfigSource (string basePath)
		{
			string config_source = SectionInformation.ConfigSource;

			if (String.IsNullOrEmpty (config_source))
				return;

			if (Path.IsPathRooted (config_source))
				throw new ConfigurationException ("The configSource attribute must be a relative physical path.");
			
			if (HasLocalModifications ())
				throw new ConfigurationException ("A section using 'configSource' may contain no other attributes or elements.");
			
			string path = Path.Combine (basePath, config_source);
			if (!File.Exists (path)) {
				RawXml = null;
				SectionInformation.SetRawXml (null);
				return;
			}
			
			RawXml = File.ReadAllText (path);
			SectionInformation.SetRawXml (RawXml);
			DeserializeElement (new ConfigXmlTextReader (new StringReader (RawXml), path), false);
		}
		

Usage Example

Example #1
0
        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)
            {
                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);
        }