0

テストに従って正しい値を返すようにクラスを変更する必要がある VSPackage を作成しています。単純に戻り値を変更するのは簡単でしたが、今は if-else ステートメントを追加して、クラスが入力に応じて異なる値を返すようにしています。

var node = new IfElseStatement
{
    Condition = new BinaryOperatorExpression
    {
        Left = new IdentifierExpression("parameterName"),
        Operator = BinaryOperatorType.Equality,
        Right = new PrimitiveExpression(3)
    },
    TrueStatement = new ReturnStatement
    {
        Expression = new PrimitiveExpression(9)
    }
};

//Visitor finds the beginnning of the method (first child is '{' so insert after that)
var parentNodeToInsert = _abstractSyntaxTree.AcceptVisitor(new FindBeginningOfMethodVisitor());
parentNodeToInsert.InsertChildAfter(parentNodeToInsert.FirstChild, node, new Role<IfElseStatement>("Statement"));

この後にブレークポイントを置いて検査するとparentNodeToInsert

ParentNodeToInsert の検査のスクリーンショット

(青いボックス)の子の下にparentNodeToInsert正しく追加されていますが、ノードの概要 (赤いボックス) には新しい if ステートメントが含まれておらず、後でtoString()構文ツリーを呼び出した場合 (ファイルに書き戻すため)それも現れません。

その理由と、それを表示する方法を知っている人はいますか?

4

0 に答える 0