Udostępnij za pośrednictwem


Metoda TextTransformation.Write — (String, array<Object )

Dołącza dane wyjściowe wygenerowany tekst sformatowany ciąg, który zawiera zero lub więcej specyfikacji formatu.Każda specyfikacja formatu zastępuje ciąg znaków reprezentujący odpowiedni argument obiektu.

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

Składnia

'Deklaracja
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: String

    Ciąg, który zawiera zero lub więcej specyfikacji formatu.

  • args
    Typ: array<Object[]

    Tablica obiektów do sformatowania.

Wyjątki

Wyjątek Warunek
ArgumentNullException

format wynosi nullodwołanie o wartości null (Nothing w języku Visual Basic).

-lub-

args wynosi nullodwołanie o wartości null (Nothing w języku Visual Basic).

FormatException

format jest nieprawidłowe.

ArgumentOutOfRangeException

Powiększanie wartości instrumentu bazowego StringBuilder przekroczyłaby MaxCapacity.

Uwagi

Write Metoda może być używana bezpośrednio w szablonie tekstu.

Przykłady

Poniższy przykład kodu demonstruje telefonicznej Write metoda z szablonu tekstu.Wklej ten kod do dowolnego pliku tekstowego, szablon i uruchamiania transformacja szablon tekst, aby zobaczyć wyniki.

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

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

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.

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

TextTransformation Klasa

Przeciążenie Write

Przestrzeń nazw Microsoft.VisualStudio.TextTemplating

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

Inne zasoby

Typy formatowania w programie .NET Framework

Numeric Format Strings

Date and Time Format Strings

Wyliczanie ciągów formatujących

How to: Append to the Generated Text