本文整理汇总了C#中InvocationExpressionSyntax.Update方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax.Update方法的具体用法?C# InvocationExpressionSyntax.Update怎么用?C# InvocationExpressionSyntax.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpressionSyntax
的用法示例。
在下文中一共展示了InvocationExpressionSyntax.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = _model.GetSymbolInfo(node.Expression).Symbol as IMethodSymbol;
if (symbol == null || !s_targetMethods.Contains(NameHelper.GetFullName(symbol)))
{
return base.VisitInvocationExpression(node);
}
int actualIndex = IndexOfParameterWithName(symbol, s_actualParamterNames);
int expectedIndex = IndexOfParameterWithName(symbol, s_expectedParamterNames);
if (actualIndex == -1 || expectedIndex == -1)
{
return base.VisitInvocationExpression(node);
}
var argumentList = (ArgumentListSyntax)Visit(node.ArgumentList);
if (!IsConstant(argumentList.Arguments[actualIndex].Expression) ||
IsConstant(argumentList.Arguments[expectedIndex].Expression))
{
// Since the arguments are already walked, use them and visit the expression
return node.Update(
(ExpressionSyntax)Visit(node.Expression),
argumentList);
}
List<ArgumentSyntax> arguments = argumentList.Arguments.ToList();
ArgumentSyntax actualArgument = arguments[actualIndex];
ArgumentSyntax expectedArgument = arguments[expectedIndex];
arguments[actualIndex] = expectedArgument;
arguments[expectedIndex] = actualArgument;
return node.Update(
(ExpressionSyntax)Visit(node.Expression),
argumentList.WithArguments(SyntaxFactory.SeparatedList(arguments)));
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:37,代码来源:AssertArgumentOrderConverter.cs
示例2: VisitInvocationExpression
public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocationSyntax)
{
var memberAccessExpressionSyntax = invocationSyntax.Expression as MemberAccessExpressionSyntax;
if(memberAccessExpressionSyntax == null)
return base.VisitInvocationExpression(invocationSyntax);
var methodNameSyntax = memberAccessExpressionSyntax.Name as GenericNameSyntax;
if(methodNameSyntax == null)
return base.VisitInvocationExpression(invocationSyntax);
if(!IsRewritableMethod(methodNameSyntax))
return base.VisitInvocationExpression(invocationSyntax);
var genericTypeNodes = methodNameSyntax.TypeArgumentList.Arguments;
var expression = invocationSyntax.Expression as MemberAccessExpressionSyntax;
var newNameSyntax = (SimpleNameSyntax)SyntaxFactory.ParseName(methodNameSyntax.Identifier.ValueText);
var newArguments = ((ArgumentListSyntax)VisitArgumentList(invocationSyntax.ArgumentList)).Arguments.ToArray();
if(genericTypeNodes.OfType<OmittedTypeArgumentSyntax>().Any())
return base.VisitInvocationExpression(invocationSyntax);
var typeArgs = genericTypeNodes
.Select(x => "\"" + x.ToFullString() + "\"")
.ConcatStrings(", ");
var newInvocationSyntax = invocationSyntax.Update(
expression
.WithName(newNameSyntax)
.WithExpression((ExpressionSyntax)base.Visit(expression.Expression)),
SyntaxFactory.ParseArgumentList($"({typeArgs})")
.AddArguments(newArguments)
);
//TODO type name is alias (using Foo = Bla.Bla.Doo);
//TODO check syntax errors before rewriting anything
//TODO rewrite explicit generator type (ClassGenerator g = ...; g.Property ...)
return newInvocationSyntax;
}