- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试用我自己构建的 InvocationExpressionSyntax 节点替换 InvocationExpressionSyntax 节点。
到目前为止,我发现的唯一方法是使用 SyntaxNode.ReplaceNodes<>,但我无法理解它的工作原理。
这是一个代码片段
public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
{
InvocationExpressionSyntax replacementNode = (constructing my own invocation node, etc.
node = (InvocationExpressionSyntax)node.ReplaceNodes(new List<InvocationExpressionSyntax>() { replacementNode /* ##Solution: This should be the EXISTING node, not the replacement node*/ }, new Func<InvocationExpressionSyntax, InvocationExpressionSyntax, SyntaxNode>((old, old2) =>
{
//return what? old and old2 are both unmodified at this point. Doing another node.replacenodes in here doesn't work either. How do I replace node?
//even the following doesn't work.
return replacementNode;
}));
}
方法的 Func<> arg 的元数据:
A function that computes a replacement node for the argument nodes. The first argument is the original node. The second argument is the same node rewritten with replaced descendants.
没有其他方法可以替换我能找到的节点。即使我返回我构建的替换节点,它也只是返回原始节点。
如何简单地替换整个节点?
最佳答案
您的代码片段让我有些困惑。 ReplaceNodes 替换第一个参数中指定的节点,因此第一个参数应该是现有 节点的列表,而不是新节点。您可以在 lambda 中为第二个参数创建新节点,然后在树中替换这些节点。如果您必须知道当前正在替换哪个节点,请查看两个参数中的第一个(在您的示例中为“旧”)以了解它是什么。
关于c# - 被 SyntaxNode.ReplaceNodes<>() 搞糊涂了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963106/
我正在尝试用我自己构建的 InvocationExpressionSyntax 节点替换 InvocationExpressionSyntax 节点。 到目前为止,我发现的唯一方法是使用 Syntax
学习本教程 http://msdn.microsoft.com/en-us/vstudio/hh543922.aspx ,我正在尝试使用应该在 SyntaxNode 类中的 ReplaceNode 方
我目前正在使用 Roslyn 对语法树进行三向合并。我在 ClassDeclerationSyntax 节点上的所有子节点之间进行了匹配,我想对这些子节点执行合并,然后基于该合并创建一棵新树。 O 是
我正在尝试使用 Roslyn 替换类的 CompilationUnitSyntax。 但是,我使用的 ReplaceNode 与 Roslyn 常见问题解答和我查看过的任何 StackOverflow
我正在尝试替换 Roslyn 语法树中的节点,这只是为了工作,但有一种烦恼,感觉它不应该是一个问题。 语法树是从脚本生成的,我希望结果也是基于脚本的语法树——但出于某种原因,替换树中的一个节点会创建一
我正在使用 XMLSlurper (groovy 1.7.4) 解析一些 XML,我需要删除一个标签(而不是让它为空!)。这是说明它的代码示例: import groovy.xml.Streaming
我是一名优秀的程序员,十分优秀!