本文整理汇总了C#中ISyntaxFactsService.IsExpressionOfMemberAccessExpression方法的典型用法代码示例。如果您正苦于以下问题:C# ISyntaxFactsService.IsExpressionOfMemberAccessExpression方法的具体用法?C# ISyntaxFactsService.IsExpressionOfMemberAccessExpression怎么用?C# ISyntaxFactsService.IsExpressionOfMemberAccessExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISyntaxFactsService
的用法示例。
在下文中一共展示了ISyntaxFactsService.IsExpressionOfMemberAccessExpression方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
});
}
}
}
}