Condividi tramite


Metodo TextTransformation.Write (String, array<Object )

Aggiunge una stringa formattata, che contiene zero o più specifiche di formato, nell'output di testo generato.Ogni specifica di formato viene sostituito dalla rappresentazione di stringa di un argomento corrispondente dell'oggetto.

Spazio dei nomi:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating.11.0 (in Microsoft.VisualStudio.TextTemplating.11.0.dll)

Sintassi

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

Parametri

  • format
    Tipo: System.String
    Stringa che contiene zero o più specifiche di formato.
  • args
    Tipo: array<System.Object[]
    Una matrice di oggetti al formato.

Eccezioni

Eccezione Condizione
ArgumentNullException

format viene nullriferimento null (Nothing in Visual Basic).

- oppure-

args viene nullriferimento null (Nothing in Visual Basic).

FormatException

format non è valido.

ArgumentOutOfRangeException

Ingrandimento del valore dell'oggetto sottostante StringBuilder eccederebbe MaxCapacity.

Note

Write il metodo può essere utilizzato direttamente nel modello di testo.

Esempi

Nell'esempio di codice seguente viene illustrato come chiamare Write metodo da un modello di testo.Incollare questo codice in qualsiasi file modello di testo ed eseguire la trasformazione del modello di testo per vedere i risultati.

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

Questo esempio produce l'output seguente:

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.

Sicurezza di .NET Framework

Vedere anche

Riferimenti

TextTransformation Classe

Overload Write

Spazio dei nomi Microsoft.VisualStudio.TextTemplating

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

Altre risorse

Formattazione dei tipi di dati

Numeric Format Strings

Date and Time Format Strings

Stringhe di formato di enumerazione

How to: Append to the Generated Text