本文整理汇总了C#中ISyntaxFactsService.GetExpressionOfMemberAccessExpression方法的典型用法代码示例。如果您正苦于以下问题:C# ISyntaxFactsService.GetExpressionOfMemberAccessExpression方法的具体用法?C# ISyntaxFactsService.GetExpressionOfMemberAccessExpression怎么用?C# ISyntaxFactsService.GetExpressionOfMemberAccessExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISyntaxFactsService
的用法示例。
在下文中一共展示了ISyntaxFactsService.GetExpressionOfMemberAccessExpression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveAwaitFromCallerIfPresent
private void RemoveAwaitFromCallerIfPresent(
SyntaxEditor editor, ISyntaxFactsService syntaxFacts,
SyntaxNode root, ReferenceLocation referenceLocation,
CancellationToken cancellationToken)
{
if (referenceLocation.IsImplicit)
{
return;
}
var location = referenceLocation.Location;
var token = location.FindToken(cancellationToken);
var nameNode = token.Parent;
if (nameNode == null)
{
return;
}
// Look for the following forms:
// await M(...)
// await <expr>.M(...)
// await M(...).ConfigureAwait(...)
// await <expr>.M(...).ConfigureAwait(...)
var expressionNode = nameNode;
if (syntaxFacts.IsNameOfMemberAccessExpression(nameNode))
{
expressionNode = nameNode.Parent;
}
if (!syntaxFacts.IsExpressionOfInvocationExpression(expressionNode))
{
return;
}
// We now either have M(...) or <expr>.M(...)
var invocationExpression = expressionNode.Parent;
Debug.Assert(syntaxFacts.IsInvocationExpression(invocationExpression));
if (syntaxFacts.IsExpressionOfAwaitExpression(invocationExpression))
{
// Handle the case where we're directly awaited.
var awaitExpression = invocationExpression.Parent;
editor.ReplaceNode(awaitExpression, (currentAwaitExpression, generator) =>
syntaxFacts.GetExpressionOfAwaitExpression(currentAwaitExpression)
.WithTriviaFrom(currentAwaitExpression));
}
else if (syntaxFacts.IsExpressionOfMemberAccessExpression(invocationExpression))
{
// Check for the .ConfigureAwait case.
var parentMemberAccessExpression = invocationExpression.Parent;
var parentMemberAccessExpressionNameNode = syntaxFacts.GetNameOfMemberAccessExpression(
parentMemberAccessExpression);
var parentMemberAccessExpressionName = syntaxFacts.GetIdentifierOfSimpleName(parentMemberAccessExpressionNameNode).ValueText;
if (parentMemberAccessExpressionName == nameof(Task.ConfigureAwait))
{
var parentExpression = parentMemberAccessExpression.Parent;
if (syntaxFacts.IsExpressionOfAwaitExpression(parentExpression))
{
var awaitExpression = parentExpression.Parent;
editor.ReplaceNode(awaitExpression, (currentAwaitExpression, generator) =>
{
var currentConfigureAwaitInvocation = syntaxFacts.GetExpressionOfAwaitExpression(currentAwaitExpression);
var currentMemberAccess = syntaxFacts.GetExpressionOfInvocationExpression(currentConfigureAwaitInvocation);
var currentInvocationExpression = syntaxFacts.GetExpressionOfMemberAccessExpression(currentMemberAccess);
return currentInvocationExpression.WithTriviaFrom(currentAwaitExpression);
});
}
}
}
}
示例2: IsViableExtensionMethod
protected override bool IsViableExtensionMethod(IMethodSymbol method, SyntaxNode expression, SemanticModel semanticModel, ISyntaxFactsService syntaxFacts, CancellationToken cancellationToken)
{
var leftExpression = syntaxFacts.GetExpressionOfMemberAccessExpression(expression) ?? syntaxFacts.GetExpressionOfConditionalMemberAccessExpression(expression);
if (leftExpression == null)
{
if (expression.IsKind(SyntaxKind.CollectionInitializerExpression))
{
leftExpression = expression.GetAncestor<ObjectCreationExpressionSyntax>();
}
else
{
return false;
}
}
var semanticInfo = semanticModel.GetTypeInfo(leftExpression, cancellationToken);
var leftExpressionType = semanticInfo.Type;
return leftExpressionType != null && method.ReduceExtensionMethod(leftExpressionType) != null;
}
示例3: IsViableExtensionMethod
protected override bool IsViableExtensionMethod(IMethodSymbol method, SyntaxNode expression, SemanticModel semanticModel, ISyntaxFactsService syntaxFacts, CancellationToken cancellationToken)
{
var leftExpression = syntaxFacts.GetExpressionOfMemberAccessExpression(expression) ?? syntaxFacts.GetExpressionOfConditionalMemberAccessExpression(expression);
if (leftExpression == null)
{
return false;
}
var semanticInfo = semanticModel.GetTypeInfo(leftExpression, cancellationToken);
var leftExpressionType = semanticInfo.Type;
return leftExpressionType != null && method.ReduceExtensionMethod(leftExpressionType) != null;
}