Roslyn如何比较令牌

时间:2017-05-24 21:29:13

标签: c# code-analysis roslyn

我写了一个函数来检查是否已经分配了一个变量,但我无法弄清楚应该如何比较节点:

    private static bool IsAssignment(SyntaxNode node)
    {
        if (node is ArgumentSyntax)
        {
            //This doesn't work even though both are ref tokens
            return node.ChildTokens().Any(t => t == SyntaxFactory.Token(SyntaxKind.RefKeyword));
        }

        return node is AssignmentExpressionSyntax;
    }

我正在考虑使用ValueText属性,但这似乎不对

当我将Child标记与语法工厂创建的标记比较时,它们不匹配我如何比较标记?

1 个答案:

答案 0 :(得分:0)

令牌比较include the parent

相反,您应该检查其do.call(Map, ...)是否为# pass all the sublists to the Map method, and collect them as lists bl <- do.call(Map, c(f=list, l)) identical(desired_list, bl) # [1] TRUE