System.Configuration.XmlUtil.CopySection C# (CSharp) Method

CopySection() private method

private CopySection ( ) : string
return string
        internal string CopySection() {
            ResetCachedStringWriter();

            // Preserve whitespace for sections for backcompat
            WhitespaceHandling originalHandling = _reader.WhitespaceHandling;
            _reader.WhitespaceHandling = WhitespaceHandling.All;

            // Create string writer to write to
            XmlUtilWriter utilWriter = new XmlUtilWriter(_cachedStringWriter, false);

            // Copy the element
            CopyElement(utilWriter);

            // Reset whitespace handling
            _reader.WhitespaceHandling = originalHandling;

            if ((originalHandling == WhitespaceHandling.None) &&
                 (Reader.NodeType  == XmlNodeType.Whitespace))  {
                // If we were previously suppose to skip whitespace, and now we
                // are at it, then lets jump to the next item
                _reader.Read();
            }

            utilWriter.Flush();
            string s = ((StringWriter)utilWriter.Writer).ToString();
            return s;
        }

Usage Example

Ejemplo n.º 1
0
        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);
                }
            }
        }
All Usage Examples Of System.Configuration.XmlUtil::CopySection