Udostępnij za pośrednictwem


Metoda TextTransformation.PushIndent —

Dodaje tekst do CurrentIndent, która jest poprzedzona do każdego wiersza danych wyjściowych generowanych tekstu.

Przestrzeń nazw:  Microsoft.VisualStudio.TextTemplating
Zestaw:  Microsoft.VisualStudio.TextTemplating.11.0 (w Microsoft.VisualStudio.TextTemplating.11.0.dll)

Składnia

'Deklaracja
Public Sub PushIndent ( _
    indent As String _
)
public void PushIndent(
    string indent
)
public:
void PushIndent(
    String^ indent
)
member PushIndent : 
        indent:string -> unit 
public function PushIndent(
    indent : String
)

Parametry

Uwagi

CurrentIndent Reprezentuje tekst, który jest prefiksem każdego wiersza danych wyjściowych generowanych tekstu.Wcięcia tekstu może być na przykład spacji, "", lub może zawierać słowa.PushIndentdodaje tekst do CurrentIndenti może być wywołana więcej, a następnie raz.PopIndentusuwa ostatnio dodany tekst z CurrentIndenti może być wywołana więcej niż jeden raz.ClearIndentUsuwa cały tekst z CurrentIndent.

Przykłady

W poniższych przykładach kodu pokazano sposób wywołania PushIndent metody z szablonu tekstu.Wkleić tych przykładów kodu do dowolnego pliku tekstowego, szablon, a następnie uruchom transformacji tekst szablonu, aby zobaczyć wyniki.

W tym przykładzie wywołuje PushIndent metodę, a następnie dodaje czterech spacji jako tiret.Warto zauważyć, że wcięcie WriteLine instrukcje w kodzie nie wpływa na wcięcie danych wyjściowych.

<#
PushIndent("    ");

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

ClearIndent();
#>
<#
PushIndent("    ")

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

ClearIndent()
#>

Ten przykład generuje następujące wyniki:

    Hello

    How are you?

    Goodbye

Poniższym przykładzie wywołuje PushIndent metoda wiele razy.Po raz pierwszy dodaje czterech spacji jako tiret dodaje dodatkowe pomieszczenia dla czterech jako tiret po raz drugi.

<#
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();
#>
<#
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()
#>

Ten przykład generuje następujące wyniki:

    Hello

    How are you?

I am fine, thank you. How are you?

    I am fine too, thank you.

    Goodbye

        Goodbye

Poniższym przykładzie wywołuje PushIndent metody i zawiera wyrazy w tekście tiret.

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

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

For i as integer = 1 To 5

    WriteLine(i.ToString())
Next

ClearIndent()
#>

Ten przykład generuje następujące wyniki:

The first five numbers:

  Number: 1

  Number: 2

  Number: 3

  Number: 4

  Number: 5

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

TextTransformation Klasa

Przestrzeń nazw Microsoft.VisualStudio.TextTemplating

CurrentIndent

PopIndent

ClearIndent

Inne zasoby

Kod generacji i szablony tekst T4