Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Studio SDK
 PushIndent Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Domain-Specific Language Tools Reference
TextTransformation..::.PushIndent Method

Updated: November 2007

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

Namespace:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating (in Microsoft.VisualStudio.TextTemplating.dll)
Visual Basic (Declaration)
Public Sub PushIndent ( _
    indent As String _
)
Visual Basic (Usage)
Dim instance As TextTransformation
Dim indent As String

instance.PushIndent(indent)
C#
public void PushIndent(
    string indent
)
Visual C++
public:
void PushIndent(
    String^ indent
)
JScript
public function PushIndent(
    indent : String
)

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.

C#
<#
PushIndent("    ");

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

ClearIndent();
#>
Visual Basic
<#
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.

C#
<#
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();
#>
Visual Basic
<#
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.

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

for(int i=1; i<6; i++)
{
    WriteLine(i.ToString());
}
ClearIndent();
#>
Visual Basic
<#
WriteLine("The first five numbers:")
PushIndent("  Number: ")

For i as integer = 1 To 5

    WriteLine(i.ToString())
Next

ClearIndent()
#>

This example produces the following output:

The first five numbers:

  Number: 1

  Number: 2

  Number: 3

  Number: 4

  Number: 5

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker