本文整理汇总了C#中CSharpSyntaxNode.DescendantNodesAndSelf方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpSyntaxNode.DescendantNodesAndSelf方法的具体用法?C# CSharpSyntaxNode.DescendantNodesAndSelf怎么用?C# CSharpSyntaxNode.DescendantNodesAndSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpSyntaxNode
的用法示例。
在下文中一共展示了CSharpSyntaxNode.DescendantNodesAndSelf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTypeDeclrationToReplace
private static TypeDeclarationSyntax FindTypeDeclrationToReplace(CSharpSyntaxNode syntaxNode)
{
TypeDeclarationSyntax typeSyntax = syntaxNode.DescendantNodesAndSelf().OfType<ClassDeclarationSyntax>().FirstOrDefault();
if (typeSyntax != null) return typeSyntax;
typeSyntax = syntaxNode.DescendantNodesAndSelf().OfType<StructDeclarationSyntax>().FirstOrDefault();
if (typeSyntax != null) return typeSyntax;
return null;
}
示例2: ReplaceClass
public static CSharpSyntaxNode ReplaceClass(CSharpSyntaxNode syntaxNode)
{
IEnumerable<TypeDeclarationSyntax> allClassSyntaxes = syntaxNode.DescendantNodesAndSelf().OfType<ClassDeclarationSyntax>();
IEnumerable<TypeDeclarationSyntax> allStructSyntaxes = syntaxNode.DescendantNodesAndSelf().OfType<StructDeclarationSyntax>();
var newSyntaxNode = syntaxNode;
TypeDeclarationSyntax currentSyntax;
while((currentSyntax = FindTypeDeclrationToReplace(newSyntaxNode))!= null)
{
newSyntaxNode = newSyntaxNode.ReplaceNode(currentSyntax, MakeInterface(currentSyntax));
}
return newSyntaxNode;
}
示例3: AddOptional
public static CSharpSyntaxNode AddOptional(CSharpSyntaxNode syntaxNode)
{
var interfaces = syntaxNode.DescendantNodesAndSelf().Where(f => f is InterfaceDeclarationSyntax);
var properties = interfaces.SelectMany(f => f.DescendantNodes().Where(c => c is PropertyDeclarationSyntax));
var methods = interfaces.SelectMany(f => f.DescendantNodes().Where(c => c is MethodDeclarationSyntax));
return syntaxNode.ReplaceNodes(properties.Concat(methods), (node, node2) =>
{
var property = node as PropertyDeclarationSyntax;
var method = node as MethodDeclarationSyntax;
if (property != null)
{
return property.WithIdentifier(SyntaxFactory.Identifier(property.Identifier.ValueText + "?"));
}
return method.WithIdentifier(SyntaxFactory.Identifier(method.Identifier.ValueText + "?"));
});
}