protected internal override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { string name = reader.Name; base.DeserializeElement(reader, serializeCollectionKey); if ((this.File != null) && (this.File.Length > 0)) { string file; string source = base.ElementInformation.Source; if (string.IsNullOrEmpty(source)) { file = this.File; } else { file = Path.Combine(Path.GetDirectoryName(source), this.File); } if (System.IO.File.Exists(file)) { int lineOffset = 0; string rawXml = null; using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlUtil util = new XmlUtil(stream, file, true)) { if (util.Reader.Name != name) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_name_value_file_section_file_invalid_root", new object[] { name }), util); } lineOffset = util.Reader.LineNumber; rawXml = util.CopySection(); while (!util.Reader.EOF) { if (util.Reader.NodeType != XmlNodeType.Comment) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_source_file_format"), util); } util.Reader.Read(); } } } ConfigXmlReader reader2 = new ConfigXmlReader(rawXml, file, lineOffset); reader2.Read(); if (reader2.MoveToNextAttribute()) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { reader2.Name }), reader2); } reader2.MoveToElement(); base.DeserializeElement(reader2, serializeCollectionKey); } } }
protected internal override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { string elementName = reader.Name; base.DeserializeElement(reader, serializeCollectionKey); if (!(File?.Length > 0)) { return; } string sourceFileFullPath; // Determine file location string configFile = ElementInformation.Source; sourceFileFullPath = string.IsNullOrEmpty(configFile) ? File : Path.Combine(Path.GetDirectoryName(configFile), File); if (!IO.File.Exists(sourceFileFullPath)) { return; } int lineOffset; string rawXml; using (Stream sourceFileStream = new FileStream(sourceFileFullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (XmlUtil xmlUtil = new XmlUtil(sourceFileStream, sourceFileFullPath, true)) { if (xmlUtil.Reader.Name != elementName) { throw new ConfigurationErrorsException( SR.Format(SR.Config_name_value_file_section_file_invalid_root, elementName), xmlUtil); } lineOffset = xmlUtil.Reader.LineNumber; rawXml = xmlUtil.CopySection(); // Detect if there is any XML left over after the section while (!xmlUtil.Reader.EOF) { XmlNodeType t = xmlUtil.Reader.NodeType; if (t != XmlNodeType.Comment) { throw new ConfigurationErrorsException(SR.Config_source_file_format, xmlUtil); } xmlUtil.Reader.Read(); } } ConfigXmlReader internalReader = new ConfigXmlReader(rawXml, sourceFileFullPath, lineOffset); internalReader.Read(); if (internalReader.MoveToNextAttribute()) { throw new ConfigurationErrorsException( SR.Format(SR.Config_base_unrecognized_attribute, internalReader.Name), (XmlReader)internalReader); } internalReader.MoveToElement(); base.DeserializeElement(internalReader, serializeCollectionKey); }
protected internal override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { string elementName = reader.Name; base.DeserializeElement(reader, serializeCollectionKey); if (!(File?.Length > 0)) return; string sourceFileFullPath; // Determine file location string configFile = ElementInformation.Source; if (string.IsNullOrEmpty(configFile)) sourceFileFullPath = File; else { string configFileDirectory = Path.GetDirectoryName(configFile); sourceFileFullPath = Path.Combine(configFileDirectory, File); } if (!IO.File.Exists(sourceFileFullPath)) return; int lineOffset; string rawXml; using ( Stream sourceFileStream = new FileStream(sourceFileFullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlUtil xmlUtil = new XmlUtil(sourceFileStream, sourceFileFullPath, true)) { if (xmlUtil.Reader.Name != elementName) { throw new ConfigurationErrorsException( string.Format(SR.Config_name_value_file_section_file_invalid_root, elementName), xmlUtil); } lineOffset = xmlUtil.Reader.LineNumber; rawXml = xmlUtil.CopySection(); // Detect if there is any XML left over after the section while (!xmlUtil.Reader.EOF) { XmlNodeType t = xmlUtil.Reader.NodeType; if (t != XmlNodeType.Comment) { throw new ConfigurationErrorsException(SR.Config_source_file_format, xmlUtil); } xmlUtil.Reader.Read(); } } } ConfigXmlReader internalReader = new ConfigXmlReader(rawXml, sourceFileFullPath, lineOffset); internalReader.Read(); if (internalReader.MoveToNextAttribute()) { throw new ConfigurationErrorsException( string.Format(SR.Config_base_unrecognized_attribute, internalReader.Name), (XmlReader)internalReader); } internalReader.MoveToElement(); base.DeserializeElement(internalReader, serializeCollectionKey); }