将文本添加到 CurrentIndent,后者将作为生成的每一行文本输出的前缀。
命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.10.0(在 Microsoft.VisualStudio.TextTemplating.10.0.dll 中)
语法
声明
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
)
参数
- indent
 类型:System.String
 要添加到 CurrentIndent 的文本。如果 CurrentIndent 已包含文本,则将 indent 追加到现有文本。
备注
CurrentIndent 表示作为生成的文本输出每一行的前缀的文本。 缩进文本可以只是空格,例如 " ",也可以包含单词。 PushIndent 将文本添加到 CurrentIndent,可以调用多次。 PopIndent 从 CurrentIndent 中删除最近添加的文本,可以调用多次。 ClearIndent 从 CurrentIndent 中移除所有文本。
示例
下面的代码示例演示如何从文本模板调用 PushIndent 方法。 将这些代码示例粘贴到任何文本模板文件中并运行文本模板转换以查看结果。
本示例将调用 PushIndent 方法,并添加四个空格作为缩进量。 注意代码中 WriteLine 语句的缩进不影响输出的缩进。
<#
PushIndent("    ");
WriteLine("Hello");
    WriteLine("How are you?");
        WriteLine("Goodbye");
ClearIndent();
#>
<#
PushIndent("    ")
WriteLine("Hello")
    WriteLine("How are you?")
        WriteLine("Goodbye")
ClearIndent()
#>
该示例产生下面的输出:
Hello
How are you?
Goodbye
下面的示例多次调用 PushIndent 方法: 第一次它添加四个空格作为缩进,第二次它添加另外四个空格作为缩进。
<#
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()
#>
该示例产生下面的输出:
Hello
How are you?
I am fine, thank you. How are you?
I am fine too, thank you.
Goodbye
Goodbye
下面的示例调用 PushIndent 方法,并包含缩进文本中的单词。
<#
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()
#>
该示例产生下面的输出:
The first five numbers:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.VisualStudio.TextTemplating 命名空间