IndentedWriter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / Serialization / IndentedWriter.cs / 1305376 / IndentedWriter.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
namespace System.Xml.Serialization { 

    using System.IO; 

    /// 
    /// 
    ///     This class will write to a stream and manage indentation. 
    /// 
    internal class IndentedWriter { 
        TextWriter writer; 
        bool needIndent;
        int indentLevel; 
        bool compact;

        internal IndentedWriter(TextWriter writer, bool compact) {
            this.writer = writer; 
            this.compact = compact;
        } 
 
        internal int Indent {
            get { 
                return indentLevel;
            }
            set {
                indentLevel = value; 
            }
        } 
 
        internal void Write(string s) {
            if (needIndent) WriteIndent(); 
            writer.Write(s);
        }

        internal void Write(char c) { 
            if (needIndent) WriteIndent();
            writer.Write(c); 
        } 

        internal void WriteLine(string s) { 
            if (needIndent) WriteIndent();
            writer.WriteLine(s);
            needIndent = true;
        } 

        internal void WriteLine() { 
            writer.WriteLine(); 
            needIndent = true;
        } 

        internal void WriteIndent() {
            needIndent = false;
            if (!compact) { 
                for (int i = 0; i < indentLevel; i++) {
                    writer.Write("    "); 
                } 
            }
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK