Пример #1
0
        /// <summary>
        /// Returns a list of all of the lines in this file.
        /// </summary>
        public IList <string> GetFileLines()
        {
            IList <string> lines       = new List <string>();
            SettingsNode   currentNode = this[0];

            while (currentNode != null)
            {
                // Write node to file
                List <string> fileComments = currentNode.GetPrecedingComments();

                for (int i = 0; i < fileComments.Count; i++)
                {
                    lines.Add(fileComments[i]);
                }

                lines.Add(NodeToFileLine(currentNode));

                // Find next line
                if (currentNode.Nodes.Count > 0)
                {
                    currentNode = currentNode.Nodes[0];
                }
                else if (currentNode.NextSibling != null)
                {
                    currentNode = currentNode.NextSibling;
                }
                else
                {
                    // Trace back to the next unread sibling
                    currentNode = currentNode.Parent;
                    while (currentNode != null)
                    {
                        if (currentNode.NextSibling == null)
                        {
                            currentNode = currentNode.Parent;
                        }
                        else
                        {
                            currentNode = currentNode.NextSibling;
                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < _trailingComments.Count; i++)
            {
                lines.Add(_trailingComments[i]);
            }

            return(lines);
        }
Пример #2
0
        /// <summary>
        /// Writes this document to the specified TextWriter.
        /// </summary>
        /// <param name="file">The file.</param>
        private void WriteToFile(TextWriter file)
        {
            SettingsNode currentNode = this[0];

            while (currentNode != null)
            {
                // Write node to file
                List <string> fileComments = currentNode.GetPrecedingComments();

                for (int i = 0; i < fileComments.Count; i++)
                {
                    file.WriteLine(fileComments[i]);
                }

                file.WriteLine(NodeToFileLine(currentNode));
                file.Flush();

                // Find next line
                if (currentNode.Nodes.Count > 0)
                {
                    currentNode = currentNode.Nodes[0];
                }
                else if (currentNode.NextSibling != null)
                {
                    currentNode = currentNode.NextSibling;
                }
                else
                {
                    // Trace back to the next unread sibling
                    currentNode = currentNode.Parent;
                    while (currentNode != null)
                    {
                        if (currentNode.NextSibling == null)
                        {
                            currentNode = currentNode.Parent;
                        }
                        else
                        {
                            currentNode = currentNode.NextSibling;
                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < _trailingComments.Count; i++)
            {
                file.WriteLine(_trailingComments[i]);
            }

            file.Flush();
        }