Export (0) Print
Expand All

TextTransformation.PushIndent Method

Adds text to CurrentIndent, which is prefixed to each line of the generated text output.

Namespace:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating.12.0 (in Microsoft.VisualStudio.TextTemplating.12.0.dll)

public void PushIndent(
	string indent
)

Parameters

indent
Type: System.String

The text to add to CurrentIndent. If CurrentIndent already contains text, indent is appended to the existing text.

The CurrentIndent represents text that is prefixed to each line of the generated text output. The indent text can be spaces only, for example "    ", or it can include words. PushIndent adds text to CurrentIndent, and can be called more then once. PopIndent removes the most recently added text from CurrentIndent, and can be called more than once. ClearIndent removes all text from the CurrentIndent.

The following code examples demonstrate how to call the PushIndent method from a text template. Paste these code examples into any text template file and run the text template transformation to see the results.

This example calls the PushIndent method and adds four spaces as the indent. Notice that the indentation of the WriteLine statements in the code does not affect the indentation of the output.

<#
PushIndent("    ");

WriteLine("Hello");
    WriteLine("How are you?");
        WriteLine("Goodbye");

ClearIndent();
#>

This example produces the following output:

    Hello

    How are you?

    Goodbye

The following example calls the PushIndent method multiple times. The first time it adds four spaces as the indent, the second time it adds an additional four spaces as the indent.

<#
PushIndent("    ");
WriteLine("Hello");
WriteLine("How are you?");

PushIndent("    ");
WriteLine("I am fine, thank you. How are you?");

PopIndent();
WriteLine("I am fine too, thank you.");
WriteLine("Goodbye");

PushIndent("    ");
WriteLine("Goodbye");

ClearIndent();
#>

This example produces the following output:

    Hello

    How are you?

        I am fine, thank you. How are you?

    I am fine too, thank you.

    Goodbye

        Goodbye

The following example calls the PushIndent method and includes words in the indent text.

<#
WriteLine("The first five numbers:");
PushIndent("  Number: ");

for(int i=1; i<6; i++)
{
    WriteLine(i.ToString());
}
ClearIndent();
#>

This example produces the following output:

The first five numbers:

  Number: 1

  Number: 2

  Number: 3

  Number: 4

  Number: 5

Show:
© 2015 Microsoft