以下代码:
CodeVariableDeclarationStatement variableDeclaration = new CodeVariableDeclarationStatement(
// Type of the variable to declare.
typeof(string),
// Name of the variable to declare.
"TestString");
生成以下VB.Net声明:
Dim TestString As String
我需要做出哪些改变才能看起来像这样:
Dim TestString As New StringBuilder()
我对如何显示新关键字感兴趣。
答案 0 :(得分:4)
在构造函数中添加CodeObjectCreateExpression
作为第三个参数:
CodeVariableDeclarationStatement variableDeclaration = new CodeVariableDeclarationStatement(
// Type of the variable to declare.
typeof(System.Text.StringBuilder),
// Name of the variable to declare.
"TestString",
// A CodeExpression that indicates the initialization expression for the variable.
new CodeObjectCreateExpression( typeof(System.Text.StringBuilder), new CodeExpression[] {} )
);