Sdílet prostřednictvím


TextTransformation.Write – metoda (String, array<Object )

Připojí výstup generovaný text formátovaný řetězec, který obsahuje žádnou nebo více specifikací formátu. Každá specifikace formátu nahrazuje řetězcové vyjádření argument objektu.

Obor názvů:  Microsoft.VisualStudio.TextTemplating
Sestavení:  Microsoft.VisualStudio.TextTemplating.10.0 (v Microsoft.VisualStudio.TextTemplating.10.0.dll)

Syntaxe

'Deklarace
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[]
)

Parametry

  • format
    Typ: System.String
    Řetězec obsahující nula nebo více specifikací formátu.
  • args
    Typ: array<System.Object[]
    Pole objektů, které mají být formátovány.

Výjimky

Výjimka Podmínka
ArgumentNullException

formatis nullodkaz Null (Nothing v jazyce Visual Basic).

-nebo-

argsis nullodkaz Null (Nothing v jazyce Visual Basic).

FormatException

format je neplatný.

ArgumentOutOfRangeException

Základní hodnota zvětšení StringBuilder by překročil MaxCapacity.

Poznámky

Write Metodu lze použít přímo v textu šablony.

Příklady

Následující příklad kódu ukazuje volání Write Metoda z textu šablony. Vložte tento kód do šablony libovolný textový soubor a spusťte transformace textu šablony výsledky.

<#
    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
#>

Tento příklad vytvoří následující výstup:

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.

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

TextTransformation Třída

Write – přetížení

Microsoft.VisualStudio.TextTemplating – obor názvů

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

Další zdroje

Typy formátování

Numeric Format Strings

Date and Time Format Strings

Provádění výčtů formátovacích řetězců

How to: Append Text to the Generated Text