내보내기(0) 인쇄
모두 확장
이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

IndentedTextWriter 클래스

탭 문자열 토큰으로 새 줄을 들여쓰기할 수 있는 텍스트 작성기를 제공합니다.

네임스페이스: System.CodeDom.Compiler
어셈블리: System(system.dll)

public class IndentedTextWriter : TextWriter
public class IndentedTextWriter extends TextWriter
public class IndentedTextWriter extends TextWriter

IndentedTextWriter는 탭 문자열을 삽입하고 현재 들여쓰기 수준을 추적하는 메서드를 제공하여 TextWriter를 확장합니다. 여러 수준의 들여쓰기로 서식을 지정한 텍스트는 생성된 코드에 유용하기 때문에, 이 클래스는 CodeDOM 코드 생성기 구현에서 사용됩니다.

탭 문자열은 각 들여쓰기가 구성하는 문자열입니다. 일반적으로 탭 문자열에는 흰색 공간이 있습니다.

Note참고

이 클래스에는 모든 멤버에 적용되는 클래스 수준의 링크 요청 및 상속 요청이 있습니다. 직접 실행 호출자나 파생 클래스에 완전 신뢰 권한이 없으면 SecurityException이 throw됩니다. 보안 요청에 대한 자세한 내용은 링크 요청상속 요청을 참조하십시오.

다음 코드 예제에서는 IndentedTextWriter를 사용하여 서로 다른 들여쓰기 수준으로 텍스트를 쓰는 방법을 보여 줍니다.

using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace IndentedTextWriterExample
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox textBox1;

        private string CreateMultilevelIndentString()
        {
            // Creates a TextWriter to use as the base output writer.
            System.IO.StringWriter baseTextWriter = new System.IO.StringWriter();            

            // Create an IndentedTextWriter and set the tab string to use 
            // as the indentation string for each indentation level.
            System.CodeDom.Compiler.IndentedTextWriter indentWriter = new IndentedTextWriter(baseTextWriter, "    ");           

            // Sets the indentation level.
            indentWriter.Indent = 0;

            // Output test strings at stepped indentations through a recursive loop method.
            WriteLevel(indentWriter, 0, 5);

            // Return the resulting string from the base StringWriter.
            return baseTextWriter.ToString();
        }

        private void WriteLevel(IndentedTextWriter indentWriter, int level, int totalLevels)
        {
            // Output a test string with a new-line character at the end.
            indentWriter.WriteLine("This is a test phrase. Current indentation level: "+level.ToString());
            
            // If not yet at the highest recursion level, call this output method for the next level of indentation.
            if( level < totalLevels )
            {
                // Increase the indentation count for the next level of indented output.
                indentWriter.Indent++;

                // Call the WriteLevel method to write test output for the next level of indentation.
                WriteLevel(indentWriter, level+1, totalLevels);

                // Restores the indentation count for this level after the recursive branch method has returned.
                indentWriter.Indent--;
            }
            else
                // Outputs a string using the WriteLineNoTabs method.
                indentWriter.WriteLineNoTabs("This is a test phrase written with the IndentTextWriter.WriteLineNoTabs method.");

            // Outputs a test string with a new-line character at the end.
            indentWriter.WriteLine("This is a test phrase. Current indentation level: "+level.ToString());           
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            textBox1.Text = CreateMultilevelIndentString();
        }

        public Form1()
        {
            System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();            
            this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right)));
            this.textBox1.Location = new System.Drawing.Point(8, 40);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(391, 242);
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "";
            button1.Location = new System.Drawing.Point(11, 8);
            button1.Name = "button1";
            button1.Size = new System.Drawing.Size(229, 23);
            button1.TabIndex = 1;
            button1.Text = "Generate string using IndentedTextWriter";
            button1.Click += new System.EventHandler(this.button1_Click);
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(407, 287);
            this.Controls.Add(button1);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "IndentedTextWriter example";
            this.ResumeLayout(false);        
        }

        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }
    }
}

package IndentedTextWriterExample; 

import System.*;
import System.CodeDom.*;
import System.CodeDom.Compiler.*;
import System.ComponentModel.*;
import System.IO.*;
import System.Windows.Forms.*;

public class Form1 extends System.Windows.Forms.Form
{
    private System.Windows.Forms.TextBox textBox1;

    private String CreateMultilevelIndentString()
    {
        // Creates a TextWriter to use as the base output writer.
        System.IO.StringWriter baseTextWriter = new System.IO.StringWriter();

        // Create an IndentedTextWriter and set the tab string to use 
        // as the indentation string for each indentation level.
        System.CodeDom.Compiler.IndentedTextWriter indentWriter 
            = new IndentedTextWriter(baseTextWriter, "    ");

        // Sets the indentation level.
        indentWriter.set_Indent(0);

        // Output test strings at stepped indentations through a 
        //recursive loop method.
        WriteLevel(indentWriter, 0, 5);

        // Return the resulting string from the base StringWriter.
        return baseTextWriter.ToString();
    } //CreateMultilevelIndentString

    private void WriteLevel(IndentedTextWriter indentWriter, int level,
        int totalLevels)
    {
        // Output a test string with a new-line character at the end.
        indentWriter.WriteLine("This is a test phrase."
            +" Current indentation level: " 
            + System.Convert.ToString(level));

        // If not yet at the highest recursion level, call this output method
        // for the next level of indentation.
        if (level < totalLevels) {
            // Increase the indentation count for the next level of
            // indented output.
            indentWriter.set_Indent(indentWriter.get_Indent() + 1);

            // Call the WriteLevel method to write test output for the
            // next level of indentation.
            WriteLevel(indentWriter, level + 1, totalLevels);

            // Restores the indentation count for this level after the
            // recursive branch method has returned.
            indentWriter.set_Indent(indentWriter.get_Indent() - 1);
        }
        // Outputs a string using the WriteLineNoTabs method.
        else {
            indentWriter.WriteLineNoTabs("This is a test phrase written with"
                +" the IndentTextWriter.WriteLineNoTabs method.");
        } 
        // Outputs a test string with a new-line character at the end.
        indentWriter.WriteLine("This is a test phrase."
            +" Current indentation level: " 
            + System.Convert.ToString(level));
    } //WriteLevel

    private void button1_Click(Object sender, System.EventArgs e)
    {
        textBox1.set_Text(CreateMultilevelIndentString());
    } //button1_Click

    public Form1()
    {
        System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.SuspendLayout();
        this.textBox1.set_Anchor(((System.Windows.Forms.AnchorStyles)(
            System.Windows.Forms.AnchorStyles.Top 
            | System.Windows.Forms.AnchorStyles.Bottom 
            | System.Windows.Forms.AnchorStyles.Left 
            | System.Windows.Forms.AnchorStyles.Right)));
        this.textBox1.set_Location(new System.Drawing.Point(8, 40));
        this.textBox1.set_Multiline(true);
        this.textBox1.set_Name("textBox1");
        this.textBox1.set_Size(new System.Drawing.Size(391, 242));
        this.textBox1.set_TabIndex(0);
        this.textBox1.set_Text("");
        button1.set_Location(new System.Drawing.Point(11, 8));
        button1.set_Name("button1");
        button1.set_Size(new System.Drawing.Size(229, 23));
        button1.set_TabIndex(1);
        button1.set_Text("Generate string using IndentedTextWriter");
        button1.add_Click(new System.EventHandler(this.button1_Click));
        this.set_AutoScaleBaseSize(new System.Drawing.Size(5, 13));
        this.set_ClientSize(new System.Drawing.Size(407, 287));
        this.get_Controls().Add(button1);
        this.get_Controls().Add(this.textBox1);
        this.set_Name("Form1");
        this.set_Text("IndentedTextWriter example");
        this.ResumeLayout(false);
    } //Form1

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main
} //Form1

System.Object
   System.MarshalByRefObject
     System.IO.TextWriter
      System.CodeDom.Compiler.IndentedTextWriter
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0, 1.1, 1.0에서 지원
이 정보가 도움이 되었습니까?
(1500자 남음)
의견을 주셔서 감사합니다.

커뮤니티 추가 항목

추가
Microsoft는 MSDN 웹 사이트에 대한 귀하의 의견을 이해하기 위해 온라인 설문 조사를 진행하고 있습니다. 참여하도록 선택하시면 MSDN 웹 사이트에서 나가실 때 온라인 설문 조사가 표시됩니다.

참여하시겠습니까?
표시:
© 2014 Microsoft. All rights reserved.