TextTransformation.WriteLine 方法 (String, array<Object )

向生成的文本输出追加默认的行终止符和包含零个或更多格式规范的设置了格式的字符串。 每个格式规范由相应对象参数的字符串表示形式替换。

命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.10.0(在 Microsoft.VisualStudio.TextTemplating.10.0.dll 中)

语法

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

参数

  • format
    类型:System.String
    一个包含零个或多个格式规范的字符串。
  • args
    类型:array<System.Object[]
    要设置其格式的对象的数组。

异常

异常 条件
ArgumentNullException

format 为 nullnull 引用(在 Visual Basic 中为 Nothing)。

- 或 -

args 为 nullnull 引用(在 Visual Basic 中为 Nothing)。

FormatException

format 无效。

ArgumentOutOfRangeException

增大基础 StringBuilder 的值,该值将超过 MaxCapacity

备注

WriteLine 方法可直接用于文本模板中。

示例

下面的代码示例演示从文本模板调用 WriteLine 方法。 将此代码粘贴到任何文本模板文件中并运行文本模板转换以查看结果。

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

WriteLine 重载

Microsoft.VisualStudio.TextTemplating 命名空间

GenerationEnvironment

StringBuilder

AppendFormat

MaxCapacity

ArgumentOutOfRangeException

FormatException

ArgumentNullException

其他资源

格式化类型

Numeric Format Strings

Date and Time Format Strings

枚举格式字符串

How to: Append Text to the Generated Text