次の方法で共有


TextTransformation.PopIndent メソッド

最後に追加されたテキストを CurrentIndent から削除します。

名前空間:  Microsoft.VisualStudio.TextTemplating
アセンブリ:  Microsoft.VisualStudio.TextTemplating.11.0 (Microsoft.VisualStudio.TextTemplating.11.0.dll 内)

構文

'宣言
Public Function PopIndent As String
public string PopIndent()
public:
String^ PopIndent()
member PopIndent : unit -> string 
public function PopIndent() : String

戻り値

型 : System.String
CurrentIndent に最後に追加されたテキストを表す StringCurrentIndent は、一般的には、戻り値をキャプチャせずに呼び出されます。

解説

CurrentIndent は、生成されたテキスト出力の各行の先頭に付加されたテキストを表します。インデント テキストには "    " のように空白のみを使用することも、単語を含めることもできます。PushIndent はテキストを CurrentIndent に追加します。このメソッドは複数回呼び出すことができます。PopIndent は最も最近追加されたテキストを CurrentIndent から削除します。このメソッドは複数回呼び出すことができます。ClearIndent は、すべてのテキストを CurrentIndent から削除します。

次のコード例は、テキスト テンプレートから PopIndent メソッドを呼び出す方法を示しています。このコードをテキスト テンプレート ファイルに貼り付け、テキスト テンプレート変換を実行して結果を表示します。

<#
PushIndent("Indent1>  ");
PushIndent("Indent2>  ");

WriteLine("Test");

string previous = PopIndent();
WriteLine("The previous indent was: {0}", previous);

PopIndent();  //Pop without capturing the return value.
WriteLine("Test");

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

WriteLine("Test")

Dim previous as String = PopIndent()
WriteLine("The previous indent was: {0}", previous)

PopIndent()  'Pop without capturing the return value.
WriteLine("Test")

ClearIndent()
#>

この例を実行すると、次の出力が生成されます。

Indent1> Indent2> Test

Indent1> The previous indent was: Indent2>

Test

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

TextTransformation クラス

Microsoft.VisualStudio.TextTemplating 名前空間

CurrentIndent

PushIndent

ClearIndent

その他の技術情報

コード生成と T4 テキスト テンプレート