2011-08-11 4 views
2

の新しいインスタンスを初期化する必要があり、次のコード:がオブジェクト

 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() 

この新しいキーワードを表示する方法は興味があります。

答えて

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[] {}) 
);