本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.DescendantNodesAndTokens方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.DescendantNodesAndTokens方法的具体用法?C# SyntaxNode.DescendantNodesAndTokens怎么用?C# SyntaxNode.DescendantNodesAndTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SyntaxNode
的用法示例。
在下文中一共展示了SyntaxNode.DescendantNodesAndTokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculate
public IEnumerable<IHalsteadMetrics> Calculate(SyntaxNode root)
{
var analyzer = new HalsteadAnalyzer();
var childNodes = root.ChildNodes().AsArray();
var types = childNodes.Where(n => n.IsKind(SyntaxKind.ClassDeclaration) || n.IsKind(SyntaxKind.StructDeclaration))
.AsArray();
var methods = types.SelectMany(n => n.ChildNodes().Where(_isMethod));
var getProperties = types.SelectMany(n => n.ChildNodes().Where(IsGetProperty));
var setProperties = types.SelectMany(n => n.ChildNodes().Where(IsSetProperty));
var looseMethods = childNodes.Where(_isMethod);
var looseGetProperties = childNodes.Where(IsGetProperty);
var looseSetProperties = childNodes.Where(IsSetProperty);
var members = methods.Concat(getProperties)
.Concat(setProperties)
.Concat(looseMethods)
.Concat(looseGetProperties)
.Concat(looseSetProperties)
.AsArray();
if (members.Any())
{
return members.Select(analyzer.Calculate);
}
var statements = childNodes.Length == 0
? root.DescendantNodesAndTokens().Select(x => SyntaxFactory.ParseStatement(x.ToFullString(), 0, new CSharpParseOptions(kind: SourceCodeKind.Script, preprocessorSymbols: new string[0])))
: childNodes.Select(x => SyntaxFactory.ParseStatement(x.ToFullString(), 0, new CSharpParseOptions(kind: SourceCodeKind.Script, preprocessorSymbols: new string[0])));
var fakeMethod = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "fake")
.WithBody(SyntaxFactory.Block(statements));
return new[]
{
analyzer.Calculate(fakeMethod)
};
}
示例2: GetNodesOrTokensToCheckForConflicts
/// <summary>
/// Gets the list of the nodes that were annotated for a conflict check
/// </summary>
private IEnumerable<ValueTuple<SyntaxNodeOrToken, RenameActionAnnotation>> GetNodesOrTokensToCheckForConflicts(
DocumentId documentId,
SyntaxNode syntaxRoot)
{
return syntaxRoot.DescendantNodesAndTokens(descendIntoTrivia: true)
.Where(s => _renameAnnotations.HasAnnotations<RenameActionAnnotation>(s))
.Select(s => ValueTuple.Create(s, _renameAnnotations.GetAnnotations<RenameActionAnnotation>(s).Single()));
}