次の方法で共有


TextTransformation.Write メソッド (String, array<Object )

0 個以上の書式指定を含む書式付き文字列を、生成されたテキスト出力の末尾に追加します。各書式指定は、対応するオブジェクト引数の文字列形式に置換されます。

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

構文

'宣言
Public Sub Write ( _
    format As String, _
    ParamArray args As Object() _
)
public void Write(
    string format,
    params Object[] args
)
public:
void Write(
    String^ format, 
    ... array<Object^>^ args
)
member Write : 
        format:string * 
        args:Object[] -> unit 
public function Write(
    format : String, 
    ... args : Object[]
)

パラメーター

  • format
    型 : System.String
    0 個以上の書式指定を含む文字列。
  • args
    型 : array<System.Object[]
    書式指定するオブジェクトの配列。

例外

例外 条件
ArgumentNullException

format は nullnull 参照 (Visual Basic では Nothing) なので、

または

args は nullnull 参照 (Visual Basic では Nothing) なので、

FormatException

format が無効です。

ArgumentOutOfRangeException

基になる StringBuilder の値を増やすと、MaxCapacity を超えます。

解説

Write メソッドはテキスト テンプレートで直接使用できます。

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

<#
    string message = @"{0}: This is text to append number {1:F}.";

    Write(message, 0, 0);          //Using the Write method
    WriteLine(null);               //Using the WriteLine method
    WriteLine(null);               //Using the WriteLine method
    
    for(int j=1; j<4; j++)
    {
        WriteLine(message, j, j);  //Using the WriteLine method
    }
#>
<#
    Dim message as String = "{0}: This is text to append number {1:F}."
    Dim j as Integer = 0

    Write(message, 0, 0)          'Using the Write method
    WriteLine(Nothing)            'Using the WriteLine method
    WriteLine(Nothing)            'Using the WriteLine method
    
    For j = 1 To 3

        WriteLine(message, j, j)  'Using the WriteLine method
    Next
#>

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

0: This is text to append number 0.00.

    

1: This is text to append number 1.00.

2: This is text to append number 2.00.

3: This is text to append number 3.00.

.NET Framework セキュリティ

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

参照

関連項目

TextTransformation クラス

Write オーバーロード

Microsoft.VisualStudio.TextTemplating 名前空間

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

その他の技術情報

型の書式設定

Numeric Format Strings

Date and Time Format Strings

列挙型書式指定文字列

How to: Append to the Generated Text