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


C# InvocationExpressionSyntax.WithExpression方法代码示例

本文整理汇总了C#中InvocationExpressionSyntax.WithExpression方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax.WithExpression方法的具体用法?C# InvocationExpressionSyntax.WithExpression怎么用?C# InvocationExpressionSyntax.WithExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InvocationExpressionSyntax的用法示例。


在下文中一共展示了InvocationExpressionSyntax.WithExpression方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            // Replace the module method name with a qualified one if this is a module ctor
            bool nodeChanged = IsInvocationAModuleCtor(node);
            ExpressionSyntax nodeExpression = nodeChanged
                ? ((IdentifierNameSyntax)node.Expression).WithIdentifier(
                    SyntaxFactory.Identifier("ConfigScript." + ((IdentifierNameSyntax)node.Expression).Identifier.Text)
                        .WithTriviaFrom(((IdentifierNameSyntax)node.Expression).Identifier))
                : node.Expression;

            // Get a hash of all the previous @doc and @ctx lambda parameters and don't replace the same
            HashSet<string> currentScopeLambdaParameters = new HashSet<string>(
                node.Ancestors().OfType<LambdaExpressionSyntax>().SelectMany(
                    x => x.DescendantNodes().OfType<ParameterSyntax>()).Select(x => x.Identifier.Text));

            // Only do the replacement if this is a module ctor or a module fluent method
            ArgumentListSyntax argumentList = node.ArgumentList;
            if(nodeChanged || IsInvocationAFluentMethod(node))
            {
                // Replace @doc and @ctx argument expressions with the appropriate lambda expressions, and stop descending if we hit another module ctor
                foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
                {
                    // Don't replace existing lambda expressions
                    if (!(argument.Expression is LambdaExpressionSyntax))
                    {
                        List<IdentifierNameSyntax> identifierNames = argument
                            .DescendantNodes(x => !(x is InvocationExpressionSyntax) || !IsInvocationAModuleCtorOrFluentMethod((InvocationExpressionSyntax)x))
                            .OfType<IdentifierNameSyntax>()
                            .Where(x => x != null && !currentScopeLambdaParameters.Contains(x.Identifier.Text))
                            .ToList();
                        IdentifierNameSyntax docReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@doc"));
                        IdentifierNameSyntax ctxReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@ctx"));
                        if (docReplacementName != null)
                        {
                            argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
                                SyntaxFactory.ParenthesizedLambdaExpression(
                                    SyntaxFactory.ParameterList(
                                        new SeparatedSyntaxList<ParameterSyntax>()
                                            .Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(docReplacementName.Identifier.Text)))
                                            .Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName == null ? "_" : ctxReplacementName.Identifier.Text)))),
                                    argument.Expression))
                                .WithTriviaFrom(argument));
                            nodeChanged = true;
                        }
                        else if (ctxReplacementName != null)
                        {
                            argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
                                SyntaxFactory.SimpleLambdaExpression(
                                    SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName.Identifier.Text)),
                                    argument.Expression))
                                .WithTriviaFrom(argument));
                            nodeChanged = true;
                        }
                    }
                }
            }

            // Build and return the result node (or just return the original node)
            return base.VisitInvocationExpression(nodeChanged ? node.WithExpression(nodeExpression).WithArgumentList(argumentList) : node);
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:60,代码来源:ConfigRewriter.cs

示例2: CreateNewInvocation

 internal static ExpressionSyntax CreateNewInvocation(InvocationExpressionSyntax invocation)
 {
     var methodName = ChangeAnyToAllAnalyzer.GetName(invocation).ToString();
     var nameToCheck = methodName == "Any" ? ChangeAnyToAllAnalyzer.allName : ChangeAnyToAllAnalyzer.anyName;
     var newInvocation = invocation.WithExpression(ChangeAnyToAllAnalyzer.CreateExpressionWithNewName(invocation, nameToCheck));
     var comparisonExpression = (ExpressionSyntax)((LambdaExpressionSyntax)newInvocation.ArgumentList.Arguments.First().Expression).Body;
     var newComparisonExpression = CreateNewComparison(comparisonExpression);
     newComparisonExpression = RemoveParenthesis(newComparisonExpression);
     newInvocation = newInvocation.ReplaceNode(comparisonExpression, newComparisonExpression);
     return newInvocation;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:ChangeAnyToAllCodeFixProvider.cs

示例3: GetCorrespondingDiagnostic

 private static DiagnosticDescriptor GetCorrespondingDiagnostic(SemanticModel semanticModel, InvocationExpressionSyntax invocation)
 {
     var methodName = (invocation?.Expression as MemberAccessExpressionSyntax)?.Name?.ToString();
     var nameToCheck = methodName == "Any" ? allName : methodName == "All" ? anyName : null;
     if (nameToCheck == null) return null;
     var invocationSymbol = semanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;
     if (invocationSymbol?.Parameters.Length != 1) return null;
     if (!IsLambdaWithoutBody(invocation)) return null;
     var otherInvocation = invocation.WithExpression(((MemberAccessExpressionSyntax)invocation.Expression).WithName(nameToCheck));
     var otherInvocationSymbol = semanticModel.GetSpeculativeSymbolInfo(invocation.SpanStart, otherInvocation, SpeculativeBindingOption.BindAsExpression);
     if (otherInvocationSymbol.Symbol == null) return null;
     if (methodName == "Any")
         return RuleAny;
     return RuleAll;
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:15,代码来源:ChangeAnyToAllAnalyzer.cs

示例4: AddAsEnumerableAsync

        private async Task<Document> AddAsEnumerableAsync(Document document, InvocationExpressionSyntax invocationExpr, CancellationToken cancellationToken)
        {
            var memberAccessExpressionSyntax = invocationExpr.Expression as MemberAccessExpressionSyntax;

            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var accessExpression = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, memberAccessExpressionSyntax.Expression, SyntaxFactory.IdentifierName("AsEnumerable"));

            var invocationExpression = SyntaxFactory.InvocationExpression(accessExpression);
            var enumerableMemberAccessExpression = memberAccessExpressionSyntax.WithExpression(invocationExpression);

            root = root.ReplaceNode(invocationExpr, invocationExpr.WithExpression(enumerableMemberAccessExpression));

            return document.WithSyntaxRoot(root);
        }
开发者ID:FeodorFitsner,项目名称:Entity-Framework-Analyzers,代码行数:15,代码来源:ConstructorCallAnalyzerCodeFixProvider.cs

示例5: GetSimplifications

        public static IEnumerable<ReplaceAction> GetSimplifications(InvocationExpressionSyntax invocation, ISemanticModel model, CancellationToken cancellationToken = default(CancellationToken))
        {
            var dotSpecial = invocation.Expression as MemberAccessExpressionSyntax;
            if (dotSpecial == null) yield break;
            var invokeWhere = dotSpecial.Expression as InvocationExpressionSyntax;
            if (invokeWhere == null) yield break;
            var dotWhere = invokeWhere.Expression as MemberAccessExpressionSyntax;
            if (dotWhere == null) yield break;

            if (!Specializations.Contains(dotSpecial.Name.Identifier.ValueText)) yield break;
            if (dotWhere.Name.Identifier.ValueText != "Where") yield break;
            var type = model.GetTypeInfo(dotWhere.Expression).Type;
            if (type == null) yield break;
            var specialGenericTypes = new[] { type.OriginalDefinition.SpecialType }.Concat(type.AllInterfaces.Select(e => e.OriginalDefinition.SpecialType));
            if (!specialGenericTypes.Contains(SpecialType.System_Collections_Generic_IEnumerable_T)) yield break;

            var better = invocation.WithExpression(dotWhere.WithName(dotSpecial.Name))
                                   .WithArgumentList(invokeWhere.ArgumentList);
            yield return new ReplaceAction(
                "Inline filter",
                invocation,
                better);
        }
开发者ID:Strilanc,项目名称:Croslyn,代码行数:23,代码来源:FilterSpecialize.cs

示例6: VisitInvocationExpression

		public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
		{
			if (this.lambdaStack.Any())
			{
				return node;
			}

			if (node.Expression.Kind() == SyntaxKind.IdentifierName)
			{
				if ((node.Expression as IdentifierNameSyntax)?.Identifier.Text == "nameof")
				{
					return node;
				}
			}
			
			var originalNodeStart = node.SpanStart + this.displacement;

			var explicitExtensionMethodCall = false;
			var result = this.semanticModel.GetSpeculativeSymbolInfo(node.SpanStart + displacement, node, SpeculativeBindingOption.BindAsExpression);

			if (result.Symbol == null)
			{
				var newNode = node.WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(node.ArgumentList.Arguments
						.Where(c => this.GetArgumentType(c) != this.cancellationTokenSymbol))));

				var visited = this.Visit(node.Expression);
				
				if (visited is MemberAccessExpressionSyntax)
				{
					var memberAccess = (MemberAccessExpressionSyntax)visited;

					if (memberAccess.Name.Identifier.Text.EndsWith("Async"))
					{
						var newExp = memberAccess.WithName(SyntaxFactory.IdentifierName(Regex.Replace(memberAccess.Name.Identifier.Text, "Async$", "")));

						newNode = newExp == null ? null : newNode.WithExpression(newExp);
					}
					else
					{
						newNode = null;
					}
				}
				else if (visited is IdentifierNameSyntax)
				{
					var identifier = (IdentifierNameSyntax)visited;

					if (identifier.Identifier.Text.EndsWith("Async"))
					{
						var newExp = identifier.WithIdentifier(SyntaxFactory.Identifier(Regex.Replace(identifier.Identifier.Text, "Async$", "")));

						newNode = newExp == null ? null : newNode.WithExpression(newExp);
					}
					else
					{
						newNode = null;
					}
				}
				else
				{
					newNode = null;
				}

				IMethodSymbol syncMethod;
				
				if (newNode != null 
					&& (syncMethod = (IMethodSymbol)(this.semanticModel.ParentModel ?? this.semanticModel).GetSpeculativeSymbolInfo(node.SpanStart, newNode, SpeculativeBindingOption.BindAsExpression).Symbol) != null)
				{
					if (syncMethod.HasRewriteAsyncApplied())
					{
						var retval = node
							.WithExpression((ExpressionSyntax)visited)
							.WithArgumentList((ArgumentListSyntax)this.VisitArgumentList(node.ArgumentList));

						var defaultExpression = SyntaxFactory.DefaultExpression(SyntaxFactory.ParseTypeName($"Task<" + syncMethod.ReturnType + ">"));
						var actualNode = this.semanticModel.SyntaxTree.GetRoot().FindNode(new TextSpan(originalNodeStart, node.Span.Length));

						this.displacement += -this.methodSyntax.SpanStart - (node.FullSpan.Length - defaultExpression.FullSpan.Length);
						this.methodSyntax = this.methodSyntax.ReplaceNode(actualNode, defaultExpression);
						this.displacement += this.methodSyntax.SpanStart;
						
						return retval;
					}
				}

				return node
					.WithExpression((ExpressionSyntax)this.Visit(node.Expression))
					.WithArgumentList((ArgumentListSyntax)this.VisitArgumentList(node.ArgumentList));
			}
			
			var methodSymbol = (IMethodSymbol)result.Symbol;
			var methodParameters = (methodSymbol.ReducedFrom ?? methodSymbol).ExtensionMethodNormalizingParameters().ToArray();

			IMethodSymbol candidate;
			int cancellationTokenPos;
			
			if (methodSymbol.HasRewriteAsyncApplied())
			{
				candidate = methodSymbol;
				cancellationTokenPos = methodParameters.TakeWhile(p => !p.IsOptional && !p.IsParams).Count();
			}
//.........这里部分代码省略.........
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:101,代码来源:MethodInvocationInspector.cs

示例7: InspectExpression

		protected override ExpressionSyntax InspectExpression(InvocationExpressionSyntax node, int cancellationTokenPos, IMethodSymbol candidate, bool explicitExtensionMethodCall)
		{
			InvocationExpressionSyntax rewrittenInvocation;

			if (node.Expression is IdentifierNameSyntax)
			{
				var identifierName = (IdentifierNameSyntax)node.Expression;

				rewrittenInvocation = node.WithExpression(identifierName.WithIdentifier(SyntaxFactory.Identifier(identifierName.Identifier.Text + "Async")));
			}
			else if (node.Expression is MemberAccessExpressionSyntax)
			{
				var memberAccessExp = (MemberAccessExpressionSyntax)node.Expression;
				var nestedInvocation = memberAccessExp.Expression as InvocationExpressionSyntax;

				if (nestedInvocation != null)
				{
					memberAccessExp = memberAccessExp.WithExpression(nestedInvocation);
				}

				if (explicitExtensionMethodCall)
				{
					rewrittenInvocation = node.WithExpression
					(
						memberAccessExp
							.WithExpression(SyntaxFactory.IdentifierName(candidate.ContainingType.ToMinimalDisplayString(this.semanticModel, node.SpanStart + displacement)))
							.WithName(memberAccessExp.Name.WithIdentifier(SyntaxFactory.Identifier(memberAccessExp.Name.Identifier.Text + "Async")))
					);

					rewrittenInvocation = rewrittenInvocation.WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList<ArgumentSyntax>().Add(SyntaxFactory.Argument(memberAccessExp.Expression.WithoutTrivia())).AddRange(node.ArgumentList.Arguments)));
				}
				else
				{
					rewrittenInvocation = node.WithExpression(memberAccessExp.WithName(memberAccessExp.Name.WithIdentifier(SyntaxFactory.Identifier(memberAccessExp.Name.Identifier.Text + "Async"))));
				}
			}
			else if (node.Expression is GenericNameSyntax)
			{
				var genericNameExp = (GenericNameSyntax)node.Expression;

				rewrittenInvocation = node.WithExpression(genericNameExp.WithIdentifier(SyntaxFactory.Identifier(genericNameExp.Identifier.Text + "Async")));
			}
			else if (node.Expression is MemberBindingExpressionSyntax && node.Parent is ConditionalAccessExpressionSyntax)
			{
				var memberBindingExpression = (MemberBindingExpressionSyntax)node.Expression;

				rewrittenInvocation = node.WithExpression(memberBindingExpression.WithName(memberBindingExpression.Name.WithIdentifier(SyntaxFactory.Identifier(memberBindingExpression.Name.Identifier.Text + "Async"))));
			}
			else
			{
				throw new InvalidOperationException($"Cannot process node of type: ({node.Expression.GetType().Name})");
			}

			if (cancellationTokenPos != -1)
			{
				var cancellationTokenArg = SyntaxFactory.Argument(SyntaxFactory.IdentifierName("cancellationToken"));

				if (explicitExtensionMethodCall)
				{
					cancellationTokenPos++;
				}
				
				if (cancellationTokenPos == rewrittenInvocation.ArgumentList.Arguments.Count)
				{
					rewrittenInvocation = rewrittenInvocation.WithArgumentList(rewrittenInvocation.ArgumentList.AddArguments(cancellationTokenArg));
				}
				else
				{
					rewrittenInvocation = rewrittenInvocation.WithArgumentList(SyntaxFactory.ArgumentList(rewrittenInvocation.ArgumentList.Arguments.Insert(cancellationTokenPos, cancellationTokenArg)));
				}
			}

			var methodInvocation = SyntaxFactory.InvocationExpression
			(
				SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, rewrittenInvocation, SyntaxFactory.IdentifierName("ConfigureAwait")),
				SyntaxFactory.ArgumentList(new SeparatedSyntaxList<ArgumentSyntax>().Add(SyntaxFactory.Argument(SyntaxFactory.ParseExpression("false"))))
			);

			var rewritten = (ExpressionSyntax)SyntaxFactory.AwaitExpression(methodInvocation);

			if (!(node.Parent is StatementSyntax))
			{
				rewritten = SyntaxFactory.ParenthesizedExpression(rewritten);
			}

			return rewritten;
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:87,代码来源:MethodInvocationAsyncRewriter.cs

示例8: RewriteStatement

 /// <summary>
 /// Rewrites the statement with a assert statement.
 /// </summary>
 /// <param name="node">InvocationExpressionSyntax</param>
 /// <returns>SyntaxNode</returns>
 private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
 {
     var rewritten = node.WithExpression(SyntaxFactory.IdentifierName("this.Assert"));
     rewritten = rewritten.WithTriviaFrom(node);
     return rewritten;
 }
开发者ID:yonglehou,项目名称:PSharp,代码行数:11,代码来源:AssertRewriter.cs

示例9: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var memberAccess = node.Expression as MemberAccessExpressionSyntax;
            if (memberAccess != null && node.ArgumentList.Arguments.Count == 1)
            {
                // check if the single method argument is an interpolated string
                var interpolatedStringSyntax = node.ArgumentList.Arguments[0].Expression as InterpolatedStringExpressionSyntax;
                if (interpolatedStringSyntax != null)
                {
                    bool appendNewLine; // this distinguishes Append and AppendLine calls
                    if (CanRewriteSymbol(_model.GetSymbolInfo(memberAccess), out appendNewLine))
                    {
                        var formatCount = 0;
                        var formatString = new StringBuilder();
                        var formatArgs = new List<ArgumentSyntax>();

                        // build the format string
                        foreach (var content in interpolatedStringSyntax.Contents)
                        {
                            switch (content.Kind())
                            {
                                case SyntaxKind.InterpolatedStringText:
                                    var text = (InterpolatedStringTextSyntax)content;
                                    formatString.Append(text.TextToken.Text);
                                    break;
                                case SyntaxKind.Interpolation:
                                    var interpolation = (InterpolationSyntax)content;
                                    formatString.Append("{");
                                    formatString.Append(formatCount++);
                                    formatString.Append(interpolation.AlignmentClause);
                                    formatString.Append(interpolation.FormatClause);
                                    formatString.Append("}");

                                    // the interpolations become arguments for the AppendFormat call
                                    formatArgs.Add(SyntaxFactory.Argument(interpolation.Expression));
                                    break;
                            }
                        }
                        if (appendNewLine)
                        {
                            formatString.AppendLine();
                        }

                        // the first parameter is the format string
                        formatArgs.Insert(0,
                            SyntaxFactory.Argument(
                                SyntaxFactory.LiteralExpression(
                                    SyntaxKind.StringLiteralExpression,
                                    SyntaxFactory.Literal(formatString.ToString()))));
                        return node
                            .WithExpression(memberAccess.WithName(SyntaxFactory.IdentifierName("AppendFormat")))
                            .WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(formatArgs)));
                    }
                }
            }
            return base.VisitInvocationExpression(node);
        }
开发者ID:m0sa,项目名称:PrecompilationDemo,代码行数:57,代码来源:StringBuilderInterpolationOptimizer.cs

示例10: ToDelayWhenAnyWhenAllAsync

        private async Task<Document> ToDelayWhenAnyWhenAllAsync(Document document, InvocationExpressionSyntax invocation, string name, CancellationToken cancellationToken)
        {
            var simpleExpression = SyntaxFactory.ParseName("");
            if (name.Equals("WaitAny"))
            {
                simpleExpression = SyntaxFactory.ParseName("System.Threading.Tasks.Task.WhenAny").WithAdditionalAnnotations(Simplifier.Annotation);
            }
            else if (name.Equals("WaitAll"))
            {
                simpleExpression = SyntaxFactory.ParseName("System.Threading.Tasks.Task.WhenAll").WithAdditionalAnnotations(Simplifier.Annotation);
            }
            else if (name.Equals("Sleep"))
            {
                simpleExpression = SyntaxFactory.ParseName("System.Threading.Tasks.Task.Delay").WithAdditionalAnnotations(Simplifier.Annotation);
            }

            SyntaxNode oldExpression = invocation;
            var expression = invocation.WithExpression(simpleExpression).WithLeadingTrivia(invocation.GetLeadingTrivia()).WithTrailingTrivia(invocation.GetTrailingTrivia());

            var newExpression = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.AwaitExpression, expression.WithLeadingTrivia(SyntaxFactory.Space)).WithTrailingTrivia(invocation.GetTrailingTrivia()).WithLeadingTrivia(invocation.GetLeadingTrivia());

            var oldroot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
            var newroot = oldroot.ReplaceNode(oldExpression, newExpression);

            var newDocument = document.WithSyntaxRoot(newroot);

            return newDocument;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:28,代码来源:BlockingAsyncCodeFix.cs

示例11: VisitInvocationExpression

		public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
		{
			if (this.lambdaStack.Any())
			{
				return node;
			}

			if (node.Expression.Kind() == SyntaxKind.IdentifierName)
			{
				if ((node.Expression as IdentifierNameSyntax)?.Identifier.Text == "nameof")
				{
					return node;
				}
			}
			
			var result = ModelExtensions.GetSpeculativeSymbolInfo(this.semanticModel, node.SpanStart + displacement, node, SpeculativeBindingOption.BindAsExpression);

			if (result.Symbol == null)
			{
				var newNode = node.WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(node.ArgumentList.Arguments
						.Where(c => this.GetArgumentType(c) != this.cancellationTokenSymbol))));

				var visited = this.Visit(node.Expression);

				if (visited is MemberAccessExpressionSyntax)
				{
					var memberAccess = (MemberAccessExpressionSyntax)visited;

					if (memberAccess.Name.Identifier.Text.EndsWith("Async"))
					{
						var newExp = memberAccess.WithName(SyntaxFactory.IdentifierName(Regex.Replace(memberAccess.Name.Identifier.Text, "Async$", "")));

						newNode = newExp == null ? null : newNode.WithExpression(newExp);
					}
					else
					{
						newNode = null;
					}
				}
				else if (visited is IdentifierNameSyntax)
				{
					var identifier = (IdentifierNameSyntax)visited;

					if (identifier.Identifier.Text.EndsWith("Async"))
					{
						var newExp = identifier.WithIdentifier(SyntaxFactory.Identifier(Regex.Replace(identifier.Identifier.Text, "Async$", "")));

						newNode = newExp == null ? null : newNode.WithExpression(newExp);
					}
					else
					{
						newNode = null;
					}
				}
				else
				{
					newNode = null;
				}

				IMethodSymbol syncMethod;

				if (newNode != null
					&& (syncMethod = (IMethodSymbol)ModelExtensions.GetSpeculativeSymbolInfo((this.semanticModel.ParentModel ?? this.semanticModel), node.SpanStart, newNode, SpeculativeBindingOption.BindAsExpression).Symbol) != null)
				{
					if (syncMethod.HasRewriteAsyncApplied())
					{
						var defaultExpression = SyntaxFactory.DefaultExpression(SyntaxFactory.ParseTypeName($"Task<" + syncMethod.ReturnType + ">"));

						return defaultExpression;
					}
				}
			}

			return node
					.WithExpression((ExpressionSyntax)this.Visit(node.Expression))
					.WithArgumentList((ArgumentListSyntax)this.VisitArgumentList(node.ArgumentList));
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:77,代码来源:GeneratedAsyncMethodSubstitutor.cs

示例12: RewriteExpression

        ExpressionSyntax RewriteExpression(InvocationExpressionSyntax node)
        {
            var identifierName = node.Expression as IdentifierNameSyntax;
            if (identifierName != null)
            {
                return SyntaxFactory.AwaitExpression(
                    node.WithExpression(identifierName.WithIdentifier(
                        SyntaxFactory.Identifier(identifierName.Identifier.Text + "Async")
                    ))
                );
            }

            var memberAccessExp = node.Expression as MemberAccessExpressionSyntax;
            if (memberAccessExp != null)
            {
                var nestedInvocation = memberAccessExp.Expression as InvocationExpressionSyntax;
                if (nestedInvocation != null)
                    memberAccessExp = memberAccessExp.WithExpression((ExpressionSyntax)VisitInvocationExpression(nestedInvocation));

                return SyntaxFactory.AwaitExpression(
                    node.WithExpression(memberAccessExp.WithName(
                        memberAccessExp.Name.WithIdentifier(SyntaxFactory.Identifier(memberAccessExp.Name.Identifier.Text + "Async"))
                    ))
                );
            }

            var genericNameExp = node.Expression as GenericNameSyntax;
            if (genericNameExp != null)
            {
                return SyntaxFactory.AwaitExpression(
                    node.WithExpression(
                        genericNameExp.WithIdentifier(SyntaxFactory.Identifier(genericNameExp.Identifier.Text + "Async"))
                    )
                );
            }

            throw new NotSupportedException($"It seems there's an expression type ({node.Expression.GetType().Name}) not yet supported by the AsyncRewriter");
        }
开发者ID:kueiwa,项目名称:AsyncRewriter,代码行数:38,代码来源:Rewriter.cs

示例13: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            var symbol = (IMethodSymbol)_model.GetSymbolInfo(node).Symbol;
            if (symbol == null)
                return node;

            // Skip invocations of methods that don't have [GenerateAsync], or an Async
            // counterpart to them
            if (!symbol.GetAttributes().Any(a => a.AttributeClass.Name == "GenerateAsync") && (
                  _excludeTypes.Contains(symbol.ContainingType) ||
                  !symbol.ContainingType.GetMembers(symbol.Name + "Async").Any()
               ))
            {
                return node;
            }

            Log.LogMessage(MessageImportance.Low, "    Found rewritable invocation: " + symbol);

            // Rewrite the method name and prefix the invocation with await
            var asIdentifierName = node.Expression as IdentifierNameSyntax;
            if (asIdentifierName != null)
            {
                ExpressionSyntax rewritten = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.AwaitExpression,
                    node.WithExpression(asIdentifierName.WithIdentifier(
                        SyntaxFactory.Identifier(asIdentifierName.Identifier.Text + "Async")
                    ))
                );
                if (!(node.Parent is StatementSyntax))
                    rewritten = SyntaxFactory.ParenthesizedExpression(rewritten);
                return rewritten;
            }

            var memberAccessExp = node.Expression as MemberAccessExpressionSyntax;
            if (memberAccessExp != null)
            {
                // Roslyn apparently doesn't visit MethodInvocationSyntax recursively, so:
                // Stream.Read().Flush() gets rewritten to await Stream.Read().FlushAsync()
                // and Read() is still sync. Opened question in the MSDN forum, for now
                // manually recurse here.
                var nestedInvocation = memberAccessExp.Expression as InvocationExpressionSyntax;
                if (nestedInvocation != null)
                    memberAccessExp = memberAccessExp.WithExpression((ExpressionSyntax)VisitInvocationExpression(nestedInvocation));

                ExpressionSyntax rewritten = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.AwaitExpression,
                    node.WithExpression(memberAccessExp.WithName(
                        memberAccessExp.Name.WithIdentifier(SyntaxFactory.Identifier(memberAccessExp.Name.Identifier.Text + "Async"))
                    ))
                );
                if (!(node.Parent is StatementSyntax))
                    rewritten = SyntaxFactory.ParenthesizedExpression(rewritten);
                return rewritten;
            }

            throw new NotSupportedException(String.Format("It seems there's an expression type ({0}) not yet supported by the AsyncGenerator", node.Expression.GetType()));
        }
开发者ID:Tradioyes,项目名称:Npgsql,代码行数:55,代码来源:GenerateAsync.cs

示例14: VisitInvocationExpression

 public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
 {
     IdentifierNameSyntax identifierName = node.Expression as IdentifierNameSyntax;
     if (identifierName != null && _moduleTypeName.Contains(identifierName.Identifier.Text))
     {
         return
             node.WithExpression(
                 identifierName.WithIdentifier(
                     SyntaxFactory.Identifier("ConfigScript." + identifierName.Identifier.Text)));
     }
     return base.VisitInvocationExpression(node);
 }
开发者ID:tareq-s,项目名称:Wyam,代码行数:12,代码来源:Configurator.cs


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