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

GetRuntimeObject() private method

private GetRuntimeObject ( ) : object
return object
		protected internal virtual object GetRuntimeObject ()
		{
			if (SectionHandler != null) {
				ConfigurationSection parentSection = sectionInformation != null ? sectionInformation.GetParentSection () : null;
				object parent = parentSection != null ? parentSection.GetRuntimeObject () : null;
				if (RawXml == null)
					return parent;
				
				try {
					// This code requires some re-thinking...
					XmlReader reader = new ConfigXmlTextReader (
						new StringReader (RawXml),
						Configuration.FilePath);

					DoDeserializeSection (reader);
					
					if (!String.IsNullOrEmpty (SectionInformation.ConfigSource)) {
						string fileDir = SectionInformation.ConfigFilePath;
						if (!String.IsNullOrEmpty (fileDir))
							fileDir = Path.GetDirectoryName (fileDir);
						else
							fileDir = String.Empty;
					
						string path = Path.Combine (fileDir, SectionInformation.ConfigSource);
						if (File.Exists (path)) {
							RawXml = File.ReadAllText (path);
							SectionInformation.SetRawXml (RawXml);
						}
					}
				} catch {
					// ignore, it can fail - we deserialize only in order to get
					// the configSource attribute
				}
				XmlDocument doc = new XmlDocument ();
				doc.LoadXml (RawXml);
				return SectionHandler.Create (parent, ConfigContext, doc.DocumentElement);
			}
			return this;
		}

Usage Example

Esempio n. 1
0
        protected override object GetRuntimeObject(object result)
        {
            object runtimeObject;
            ConfigurationSection section = result as ConfigurationSection;

            if (section == null)
            {
                runtimeObject = result;
            }
            else
            {
                // Call into config section while impersonating process or UNC identity
                // so that the section could read files from disk if needed
                try
                {
                    runtimeObject = section.GetRuntimeObject();
                }
                catch (Exception e)
                {
                    throw new ConfigurationErrorsException(
                              SR.Format(SR.Config_exception_in_config_section_handler,
                                        section.SectionInformation.SectionName), e);
                }
            }

            return(runtimeObject);
        }
All Usage Examples Of System.Configuration.ConfigurationSection::GetRuntimeObject