1 //------------------------------------------------------------------------------
2 // <copyright file="IndentTextWriter.cs" company="Microsoft">
4 // <OWNER>Microsoft</OWNER>
5 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //------------------------------------------------------------------------------
9 namespace System
.CodeDom
.Compiler
{
11 using System
.Diagnostics
;
15 using System
.Security
.Permissions
;
16 using System
.Globalization
;
19 /// <para>Provides a text writer that can indent new lines by a tabString token.</para>
21 public class IndentedTextWriter
: TextWriter
{
22 private TextWriter writer
;
23 private int indentLevel
;
24 private bool tabsPending
;
25 private string tabString
;
28 /// <para>[To be supplied.]</para>
30 public const string DefaultTabString
= " ";
34 /// Initializes a new instance of <see cref='System.CodeDom.Compiler.IndentedTextWriter'/> using the specified
35 /// text writer and default tab string.
38 public IndentedTextWriter(TextWriter writer
) : this(writer
, DefaultTabString
) {
43 /// Initializes a new instance of <see cref='System.CodeDom.Compiler.IndentedTextWriter'/> using the specified
44 /// text writer and tab string.
47 public IndentedTextWriter(TextWriter writer
, string tabString
): base(CultureInfo
.InvariantCulture
) {
49 this.tabString
= tabString
;
55 /// <para>[To be supplied.]</para>
57 public override Encoding Encoding
{
59 return writer
.Encoding
;
65 /// Gets or sets the new line character to use.
68 public override string NewLine
{
70 return writer
.NewLine
;
74 writer
.NewLine
= value;
80 /// Gets or sets the number of spaces to indent.
88 Debug
.Assert(value >= 0, "Bogus Indent... probably caused by mismatched Indent++ and Indent--");
98 /// Gets or sets the TextWriter to use.
101 public TextWriter InnerWriter
{
107 internal string TabString
{
108 get { return tabString; }
113 /// Closes the document being written to.
116 public override void Close() {
121 /// <para>[To be supplied.]</para>
123 public override void Flush() {
128 /// <para>[To be supplied.]</para>
130 protected virtual void OutputTabs() {
132 for (int i
=0; i
< indentLevel
; i
++) {
133 writer
.Write(tabString
);
142 /// to the text stream.
145 public override void Write(string s
) {
152 /// Writes the text representation of a Boolean value to the text stream.
155 public override void Write(bool value) {
162 /// Writes a character to the text stream.
165 public override void Write(char value) {
173 /// character array to the text stream.
176 public override void Write(char[] buffer
) {
178 writer
.Write(buffer
);
183 /// Writes a subarray
184 /// of characters to the text stream.
187 public override void Write(char[] buffer
, int index
, int count
) {
189 writer
.Write(buffer
, index
, count
);
194 /// Writes the text representation of a Double to the text stream.
197 public override void Write(double value) {
204 /// Writes the text representation of
205 /// a Single to the text
209 public override void Write(float value) {
216 /// Writes the text representation of an integer to the text stream.
219 public override void Write(int value) {
226 /// Writes the text representation of an 8-byte integer to the text stream.
229 public override void Write(long value) {
236 /// Writes the text representation of an object
237 /// to the text stream.
240 public override void Write(object value) {
247 /// Writes out a formatted string, using the same semantics as specified.
250 public override void Write(string format
, object arg0
) {
252 writer
.Write(format
, arg0
);
257 /// Writes out a formatted string,
258 /// using the same semantics as specified.
261 public override void Write(string format
, object arg0
, object arg1
) {
263 writer
.Write(format
, arg0
, arg1
);
268 /// Writes out a formatted string,
269 /// using the same semantics as specified.
272 public override void Write(string format
, params object[] arg
) {
274 writer
.Write(format
, arg
);
279 /// Writes the specified
280 /// string to a line without tabs.
283 public void WriteLineNoTabs(string s
) {
289 /// Writes the specified string followed by
290 /// a line terminator to the text stream.
293 public override void WriteLine(string s
) {
301 /// Writes a line terminator.
304 public override void WriteLine() {
312 /// Writes the text representation of a Boolean followed by a line terminator to
316 public override void WriteLine(bool value) {
318 writer
.WriteLine(value);
323 /// <para>[To be supplied.]</para>
325 public override void WriteLine(char value) {
327 writer
.WriteLine(value);
332 /// <para>[To be supplied.]</para>
334 public override void WriteLine(char[] buffer
) {
336 writer
.WriteLine(buffer
);
341 /// <para>[To be supplied.]</para>
343 public override void WriteLine(char[] buffer
, int index
, int count
) {
345 writer
.WriteLine(buffer
, index
, count
);
350 /// <para>[To be supplied.]</para>
352 public override void WriteLine(double value) {
354 writer
.WriteLine(value);
359 /// <para>[To be supplied.]</para>
361 public override void WriteLine(float value) {
363 writer
.WriteLine(value);
368 /// <para>[To be supplied.]</para>
370 public override void WriteLine(int value) {
372 writer
.WriteLine(value);
377 /// <para>[To be supplied.]</para>
379 public override void WriteLine(long value) {
381 writer
.WriteLine(value);
386 /// <para>[To be supplied.]</para>
388 public override void WriteLine(object value) {
390 writer
.WriteLine(value);
395 /// <para>[To be supplied.]</para>
397 public override void WriteLine(string format
, object arg0
) {
399 writer
.WriteLine(format
, arg0
);
404 /// <para>[To be supplied.]</para>
406 public override void WriteLine(string format
, object arg0
, object arg1
) {
408 writer
.WriteLine(format
, arg0
, arg1
);
413 /// <para>[To be supplied.]</para>
415 public override void WriteLine(string format
, params object[] arg
) {
417 writer
.WriteLine(format
, arg
);
422 /// <para>[To be supplied.]</para>
424 [CLSCompliant(false)]
425 public override void WriteLine(UInt32
value) {
427 writer
.WriteLine(value);
431 internal void InternalOutputTabs() {
432 for (int i
=0; i
< indentLevel
; i
++) {
433 writer
.Write(tabString
);
438 internal class Indentation
{
439 private IndentedTextWriter writer
;
443 internal Indentation(IndentedTextWriter writer
, int indent
) {
444 this.writer
= writer
;
445 this.indent
= indent
;
449 internal string IndentationString
{
452 string tabString
= writer
.TabString
;
453 StringBuilder sb
= new StringBuilder(indent
* tabString
.Length
);
454 for( int i
= 0; i
< indent
; i
++) {
455 sb
.Append(tabString
);