当前位置: 首页>>代码示例>>C#>>正文


C# InvocationExpressionSyntax.Update方法代码示例

本文整理汇总了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;
        }
开发者ID:VitalyTVA,项目名称:MetaSharp,代码行数:36,代码来源:Rewriter.cs


注:本文中的InvocationExpressionSyntax.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。