public object Create(object parent, object configContext, XmlNode section) { object result = parent; // parse XML XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); result = NameValueSectionHandler.CreateStatic(result, section); if (fileAttribute != null && fileAttribute.Value.Length != 0) { string filename = null; filename = fileAttribute.Value; IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return(null); } string configFile = configXmlNode.Filename; string directory = Path.GetDirectoryName(configFile); string sourceFileFullPath = Path.Combine(directory, filename); if (File.Exists(sourceFileFullPath)) { ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(sourceFileFullPath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, sourceFileFullPath, e.LineNumber); } if (section.Name != doc.DocumentElement.Name) { throw new ConfigurationErrorsException( SR.Format(SR.Config_name_value_file_section_file_invalid_root, section.Name), doc.DocumentElement); } result = NameValueSectionHandler.CreateStatic(result, doc.DocumentElement); } } return(result); }
public object Create(object parent, object configContext, XmlNode section) { object obj2 = parent; XmlNode node = section.Attributes.RemoveNamedItem("file"); obj2 = NameValueSectionHandler.CreateStatic(obj2, section); if ((node == null) || (node.Value.Length == 0)) { return(obj2); } string str = null; str = node.Value; IConfigErrorInfo info = node as IConfigErrorInfo; if (info == null) { return(null); } string path = Path.Combine(Path.GetDirectoryName(info.Filename), str); if (!File.Exists(path)) { return(obj2); } ConfigXmlDocument document = new ConfigXmlDocument(); try { document.Load(path); } catch (XmlException exception) { throw new ConfigurationErrorsException(exception.Message, exception, path, exception.LineNumber); } if (section.Name != document.DocumentElement.Name) { throw new ConfigurationErrorsException(System.SR.GetString("Config_name_value_file_section_file_invalid_root", new object[] { section.Name }), document.DocumentElement); } return(NameValueSectionHandler.CreateStatic(obj2, document.DocumentElement)); }