Domain-Specific Language Tools 
How to: Append Text to the Generated Text 

The following procedure demonstrates using the Write and WriteLine methods to append text to a generated output file. Use these methods within helper functions to add text to the output.

To use the Write and WriteLine methods in a text template

  1. In Solution Explorer, right-click the text template file that you want to edit and then click Open.

    The template opens in the editor.

  2. Add the following code with the Write and WriteLine methods to the template:

    C#
    <#
        string item = @"This is my additonal text I want to append to my output file";
        
        for(int i=1; i<4; i++)
        {
            <b>WriteLine</b>(item);  //Using the WriteLine method
        }
        <b>WriteLine</b>(null);
    
        <b>Write</b>(item);  //Using the Write method
    #>

    Visual Basic
    <#
        Dim item As String = "This is my additonal text I want to append to my output file"
        Dim i as Integer = 0
        
        For i = 1 To 3
    
            <b>WriteLine</b>(item)  'Using the WriteLine method
        Next
    
        <b>WriteLine</b>("")
    
        <b>Write</b>(item)  'Using the Write method
    #>
    NoteNote

    The Write and WriteLine methods also have overload methods which take (String, Object[]) as arguments. For more information, see Write and WriteLine.

For an illustration of appending generated text to a helper class within the context of creating and using a complete text template, see Walkthrough: Creating and Running Text Templates.

NoteNote

To debug text templates you must set the debug parameter of the template directive. For more information, see How to: Debug Text Templates.

Security

For more information, see Security of Text Templates.

See Also

Tags :


Page view tracker