本文整理汇总了C#中InvocationExpressionSyntax.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax.DescendantNodes方法的具体用法?C# InvocationExpressionSyntax.DescendantNodes怎么用?C# InvocationExpressionSyntax.DescendantNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpressionSyntax
的用法示例。
在下文中一共展示了InvocationExpressionSyntax.DescendantNodes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckForCondition
private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode,
SyntaxNode expressionStatementParent, DiagnosticDescriptor descriptor)
{
if ((!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) &&
!(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false))
{
context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation()));
}
}
示例2: CheckForCondition
private static void CheckForCondition(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocationNode,
SyntaxNode expressionStatementParent, DiagnosticDescriptor descriptor)
{
// Make sure the invocation's containing type is not the same as the class that contains it
if ((invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.DotToken)) &&
!invocationNode.DescendantNodesAndTokens().Any(_ => _.IsKind(SyntaxKind.ThisExpression) || _.IsKind(SyntaxKind.BaseExpression))) &&
(!expressionStatementParent?.DescendantNodesAndTokens()?.Any(_ => _.IsKind(SyntaxKind.EqualsToken)) ?? false) &&
!(invocationNode.DescendantNodes()?.Any(_ => new ContainsInvocationExpressionWalker(_).HasIssue) ?? false) &&
!FindSaveAssignmentIssueAnalyzer.IsReturnValue(invocationNode))
{
context.ReportDiagnostic(Diagnostic.Create(descriptor, invocationNode.GetLocation()));
}
}
示例3: ValidateInvocation
static bool ValidateInvocation(InvocationExpressionSyntax expr)
{
// Okay => x = M(), var x = M(), return M(), from x in M(), (bool) ? M() : M()
if (expr.Parent.IsKind(SyntaxKind.SimpleAssignmentExpression)) return true;
if (expr.Parent.IsKind(SyntaxKind.EqualsValueClause) && expr.Parent.Parent.IsKind(SyntaxKind.VariableDeclarator)) return true;
if (expr.Parent.IsKind(SyntaxKind.ReturnStatement)) return true;
if (expr.Parent.IsKind(SyntaxKind.FromClause)) return true;
if (expr.Parent.IsKind(SyntaxKind.ConditionalExpression)) return true;
// Okay => M().M()
if (expr.DescendantNodes().OfType<InvocationExpressionSyntax>().Any()) return true;
return false;
}
示例4: ValidateInvocation
static bool ValidateInvocation(InvocationExpressionSyntax expr)
{
bool allAncestorsIsParenthes = true;
foreach (var x in expr.Ancestors())
{
// scope is in lambda, method
if (x.IsKind(SyntaxKind.SimpleLambdaExpression) || x.IsKind(SyntaxKind.ParenthesizedLambdaExpression) || x.IsKind(SyntaxKind.ArrowExpressionClause))
{
// () => M()
if (allAncestorsIsParenthes) return true;
break;
}
if (x.IsKind(SyntaxKind.MethodDeclaration)) break;
if (x.IsKind(SyntaxKind.PropertyDeclaration)) break;
if (x.IsKind(SyntaxKind.ConstructorDeclaration)) break;
// x = M()
if (x.IsKind(SyntaxKind.SimpleAssignmentExpression)) return true;
// var x = M()
if (x.IsKind(SyntaxKind.VariableDeclarator)) return true;
// return M()
if (x.IsKind(SyntaxKind.ReturnStatement)) return true;
// from x in M()
if (x.IsKind(SyntaxKind.FromClause)) return true;
// (bool) ? M() : M()
if (x.IsKind(SyntaxKind.ConditionalExpression)) return true;
// M(M())
if (x.IsKind(SyntaxKind.InvocationExpression)) return true;
// new C(M())
if (x.IsKind(SyntaxKind.ObjectCreationExpression)) return true;
// (((((M()))))
if (!x.IsKind(SyntaxKind.ParenthesizedExpression))
{
allAncestorsIsParenthes = false;
}
}
// Okay => M().M()
if (expr.DescendantNodes().OfType<InvocationExpressionSyntax>().Any()) return true;
return false;
}
示例5: GetMethodName
private SyntaxNode GetMethodName(InvocationExpressionSyntax invocation)
{
// The left parentheses is the rightmost position for the method name.
int rightMost = invocation.ArgumentList.OpenParenToken.Span.Start;
// Order the decendents by its span
var orderedDecendents = invocation.DescendantNodes().OrderBy(n => n.Span.Length);
// The decendent whose length is the most and end is before ( should be method name node.
return orderedDecendents.Last(n => n.Span.End <= rightMost);
}