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


C# InvocationExpressionSyntax.WithArgumentList方法代码示例

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


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

示例1: VisitInvocationExpression

        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
        {
            // 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;
            bool nodeChanged = false;
            if(IsInvocationAModuleCtorOrFluentMethod(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.WithArgumentList(argumentList) : node);
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:53,代码来源:LambdaRewriter.cs

示例2: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a send statement.
        /// </summary>
        /// <param name="node">LocalDeclarationStatementSyntax</param>
        /// <returns>StatementSyntax</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);

            arguments[1] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[1].ToString() + "()"));

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression(SyntaxFactory.IdentifierName("this.Send")).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:19,代码来源:SendRewriter.cs

示例3: AddCancellationTokenAsync

        private async Task<Document> AddCancellationTokenAsync(Document document, InvocationExpressionSyntax invocation, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(false);

            ITypeSymbol cancellationTokenType = semanticModel.Compilation.GetTypeByMetadataName("System.Threading.CancellationToken");

            var invocationSymbol = semanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol;

            // Step up through the syntax tree to get the Method Declaration of the invocation
            var parent = invocation.Parent;
            parent = parent.FirstAncestorOrSelf<MethodDeclarationSyntax>();

            var containingMethod = semanticModel.GetDeclaredSymbol(parent) as IMethodSymbol;

            // Get the CancellationToken from the containing method
            var tokens = containingMethod.Parameters.Where(x => x.Type.Equals(cancellationTokenType));

            var firstToken = tokens.FirstOrDefault();

            // Get what slot to put it in
            var cancelSlots = invocationSymbol.Parameters.Where(x => x.Type.Equals(cancellationTokenType));

            if (cancelSlots.FirstOrDefault() == null)
            {
                return document;
            }

            var firstSlotIndex = invocationSymbol.Parameters.IndexOf(cancelSlots.FirstOrDefault());
            var newIdentifier = SyntaxFactory.IdentifierName(firstToken.Name.ToString());
            var newArgs = invocation.ArgumentList.Arguments;

            if (firstSlotIndex == 0)
            {
                newArgs = newArgs.Insert(firstSlotIndex, SyntaxFactory.Argument(newIdentifier).WithLeadingTrivia());
            }
            else
            {
                newArgs = invocation.ArgumentList.Arguments.Insert(firstSlotIndex, SyntaxFactory.Argument(newIdentifier).WithLeadingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ElasticSpace)));
            }

            var newArgsList = SyntaxFactory.ArgumentList(newArgs);
            var newInvocation = invocation.WithArgumentList(newArgsList);

            var oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
            var newRoot = oldRoot.ReplaceNode(invocation, newInvocation);
            var newDocument = document.WithSyntaxRoot(newRoot);

            // Return document with transformed tree.
            return newDocument;
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:50,代码来源:CancellationCodeFix.cs

示例4: VisitInvocationExpression

		/// <summary>
		///     Reorders the named arguments of the <paramref name="invocation" />.
		/// </summary>
		public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
		{
			// Nothing to do if no named arguments are used
			if (invocation.ArgumentList.Arguments.All(argument => argument.NameColon == null))
				return base.VisitInvocationExpression(invocation);

			// Determine the correct order of the arguments, recursively normalize the arguments and remove the argument name
			var orderedArguments =
				from argument in invocation.ArgumentList.Arguments
				let parameterSymbol = argument.GetParameterSymbol(SemanticModel)
				orderby parameterSymbol.Ordinal
				select ((ArgumentSyntax)VisitArgument(argument)).WithNameColon(null);

			var argumentList = SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(orderedArguments));
			return invocation.WithArgumentList(argumentList).NormalizeWhitespace();
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:19,代码来源:NamedArgumentNormalizer.cs

示例5: VisitInvocationExpression

 public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
 {
     var memAccess = node.Expression as MemberAccessExpressionSyntax;
     if (memAccess != null)
     {
         var expression = GetRoleMethodInvocation(memAccess);
         var arguments = from arg in node.ArgumentList.Arguments
                         select (ArgumentSyntax)Visit(arg);
         var args = new SeparatedSyntaxList<ArgumentSyntax>().Add(arguments.ToArray());
         node = node.WithArgumentList(Syntax.ArgumentList(args));
         if (expression != node.Expression)
         {
             node = node.ReplaceNode(node.Expression, expression);
         }
     }
     return base.VisitInvocationExpression(node);
 }
开发者ID:runefs,项目名称:Interact,代码行数:17,代码来源:ExpressionRewriter.cs

示例6: RewriteStatement

        /// <summary>
        /// Rewrites the expression with a create remote machine expression.
        /// </summary>
        /// <param name="node">InvocationExpressionSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);
            arguments.Add(node.ArgumentList.Arguments[0]);
            arguments.Add(node.ArgumentList.Arguments[1]);

            if (node.ArgumentList.Arguments.Count > 2)
            {
                arguments.Add(node.ArgumentList.Arguments[2]);

                string payload = "";
                for (int i = 3; i < node.ArgumentList.Arguments.Count; i++)
                {
                    if (i == node.ArgumentList.Arguments.Count - 1)
                    {
                        payload += node.ArgumentList.Arguments[i].ToString();
                    }
                    else
                    {
                        payload += node.ArgumentList.Arguments[i].ToString() + ", ";
                    }
                }

                arguments[2] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                    "new " + arguments[2].ToString() + "(" + payload + ")"));
            }

            var machineIdentifier = arguments[0].ToString();
            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(
                SyntaxFactory.IdentifierName(machineIdentifier)));

            var text = "this.CreateRemoteMachine";

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression(SyntaxFactory.IdentifierName(text)).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:45,代码来源:CreateRemoteMachineRewriter.cs

示例7: 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

示例8: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a monitor statement.
        /// </summary>
        /// <param name="node">LocalDeclarationStatementSyntax</param>
        /// <returns>StatementSyntax</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            if (this.Project.CompilationContext.ActiveCompilationTarget != CompilationTarget.Testing)
            {
                this.ToRemove.Add(node.Parent);
                return node;
            }

            var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "()"));

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression((node.Expression as GenericNameSyntax).
                WithIdentifier(SyntaxFactory.Identifier("this.Monitor"))).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:26,代码来源:MonitorRewriter.cs

示例9: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a monitor statement.
        /// </summary>
        /// <param name="node">LocalDeclarationStatementSyntax</param>
        /// <returns>StatementSyntax</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>();
            arguments.Add(node.ArgumentList.Arguments[0]);

            string payload = "";
            for (int i = 1; i < node.ArgumentList.Arguments.Count; i++)
            {
                if (i == node.ArgumentList.Arguments.Count - 1)
                {
                    payload += node.ArgumentList.Arguments[i].ToString();
                }
                else
                {
                    payload += node.ArgumentList.Arguments[i].ToString() + ", ";
                }
            }

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "(" + payload + ")"));

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression((node.Expression as GenericNameSyntax).
                WithIdentifier(SyntaxFactory.Identifier("this.Monitor"))).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:34,代码来源:MonitorRewriter.cs

示例10: AddArgument

        static InvocationExpressionSyntax AddArgument(InvocationExpressionSyntax invocationExpression, IParameterSymbol parameterToAdd, bool isNextInSequence)
        {
            ExpressionSyntax defaultValue;
            if (parameterToAdd.HasExplicitDefaultValue)
            {
                defaultValue = ComputeConstantValueCodeRefactoringProvider.GetLiteralExpression(parameterToAdd.ExplicitDefaultValue);
            }
            else
            {
                return invocationExpression;
            }
            ArgumentSyntax newArgument = SyntaxFactory.Argument(defaultValue);
            if (invocationExpression.ArgumentList.Arguments.Any(argument => argument.NameColon != null) || !isNextInSequence)
            {
                newArgument = newArgument.WithNameColon(SyntaxFactory.NameColon(parameterToAdd.Name));
            }

            var newArguments = invocationExpression.ArgumentList.AddArguments(newArgument);
            return invocationExpression.WithArgumentList(newArguments);
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:20,代码来源:AddOptionalParameterToInvocationCodeRefactoringProvider.cs

示例11: RewriteStatement

        /// <summary>
        /// Rewrites the expression with a create machine expression.
        /// </summary>
        /// <param name="node">InvocationExpressionSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);
            var machineIdentifier = arguments[0].ToString();

            SyntaxNode models = null;

            var parent = node.FirstAncestorOrSelf<ExpressionStatementSyntax>();
            if (parent != null)
            {
                models = base.GetNextStatement(parent);
                if (models != null &&
                    (models is LocalDeclarationStatementSyntax) &&
                    (models as LocalDeclarationStatementSyntax).Declaration.
                    Type.ToString().Equals("models"))
                {
                    if (this.Project.CompilationContext.ActiveCompilationTarget != CompilationTarget.Testing)
                    {
                        machineIdentifier = (models as LocalDeclarationStatementSyntax).
                            Declaration.Variables[0].Identifier.ValueText;
                    }
                }
                else
                {
                    models = null;
                }
            }

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(
                SyntaxFactory.IdentifierName(machineIdentifier)));

            var text = "";
            if (base.IsMonitor(machineIdentifier))
            {
                if (this.Project.CompilationContext.ActiveCompilationTarget != CompilationTarget.Testing)
                {
                    this.ToRemove.Add(node);
                    if (models != null)
                    {
                        this.ToRemove.Add(models);
                    }

                    return node;
                }

                text += "this.CreateMonitor";
            }
            else
            {
                text += "this.CreateMachine";
            }

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression(SyntaxFactory.IdentifierName(text)).
                WithTriviaFrom(node);

            if (models != null)
            {
                node = node.WithoutTrailingTrivia();
                this.ToReplace.Add(models);
            }

            return rewritten;
        }
开发者ID:ashwini-mnnit,项目名称:PSharp,代码行数:70,代码来源:CreateMachineRewriter.cs

示例12: RewriteStatement

        /// <summary>
        /// Rewrites the statement with a monitor statement.
        /// </summary>
        /// <param name="node">LocalDeclarationStatementSyntax</param>
        /// <returns>StatementSyntax</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            if (!Configuration.RunStaticAnalysis &&
                !Configuration.RunDynamicAnalysis)
            {
                this.ToRemove.Add(node.Parent);
                return node;
            }

            var arguments = new List<ArgumentSyntax>(node.ArgumentList.Arguments);

            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                "new " + arguments[0].ToString() + "()"));

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression((node.Expression as GenericNameSyntax).
                WithIdentifier(SyntaxFactory.Identifier("this.Monitor"))).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:27,代码来源:MonitorRewriter.cs

示例13: 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

示例14: AddArguments

		private static InvocationExpressionSyntax AddArguments(CodeFixContext context, 
			IMethodSymbol methodSymbol, InvocationExpressionSyntax invocation)
		{
			context.CancellationToken.ThrowIfCancellationRequested();

			var argumentCount = methodSymbol.Parameters.Length;
			if (argumentCount > 0)
			{
				// Define an argument list.
				var arguments = new SyntaxNodeOrToken[(2 * argumentCount) - 1];

				for (var i = 0; i < argumentCount; i++)
				{
					var parameter = methodSymbol.Parameters[i];
					var argument = SyntaxFactory.Argument(
						SyntaxFactory.IdentifierName(parameter.Name));

					if (parameter.RefKind.HasFlag(RefKind.Ref))
					{
						argument = argument.WithRefOrOutKeyword(
							SyntaxFactory.Token(SyntaxKind.RefKeyword));
					}
					else if (parameter.RefKind.HasFlag(RefKind.Out))
					{
						argument = argument.WithRefOrOutKeyword(
							SyntaxFactory.Token(SyntaxKind.OutKeyword));
					}

					arguments[2 * i] = argument;

					if (i < argumentCount - 1)
					{
						arguments[(2 * i) + 1] = SyntaxFactory.Token(SyntaxKind.CommaToken);
					}
				}

				invocation = invocation.WithArgumentList(
					SyntaxFactory.ArgumentList(
						SyntaxFactory.SeparatedList<ArgumentSyntax>(arguments))
					.WithOpenParenToken(SyntaxFactory.Token(SyntaxKind.OpenParenToken))
					.WithCloseParenToken(SyntaxFactory.Token(SyntaxKind.CloseParenToken)));
			}

			return invocation;
		}
开发者ID:JasonBock,项目名称:CompilerAPIBook,代码行数:45,代码来源:MustInvokeBaseMethodCallMethodCodeFix.cs

示例15: RewriteStatement

        /// <summary>
        /// Rewrites the expression with a create machine expression.
        /// </summary>
        /// <param name="node">InvocationExpressionSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
        {
            var arguments = new List<ArgumentSyntax>();
            arguments.Add(node.ArgumentList.Arguments[0]);

            if (node.ArgumentList.Arguments.Count > 1)
            {
                arguments.Add(node.ArgumentList.Arguments[1]);

                int eventIndex = 1;
                if (arguments[1].ToString().StartsWith("\"") &&
                    arguments[1].ToString().EndsWith("\""))
                {
                    eventIndex++;
                }

                if (node.ArgumentList.Arguments.Count > eventIndex)
                {
                    if (eventIndex == 2)
                    {
                        arguments.Add(node.ArgumentList.Arguments[eventIndex]);
                    }

                    string payload = "";
                    for (int i = eventIndex + 1; i < node.ArgumentList.Arguments.Count; i++)
                    {
                        if (i == node.ArgumentList.Arguments.Count - 1)
                        {
                            payload += node.ArgumentList.Arguments[i].ToString();
                        }
                        else
                        {
                            payload += node.ArgumentList.Arguments[i].ToString() + ", ";
                        }
                    }

                    arguments[eventIndex] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
                        "new " + arguments[eventIndex].ToString() + "(" + payload + ")"));
                }
            }

            var machineIdentifier = arguments[0].ToString();
            arguments[0] = SyntaxFactory.Argument(SyntaxFactory.TypeOfExpression(
                SyntaxFactory.IdentifierName(machineIdentifier)));

            string text = "this.CreateMachine";

            var rewritten = node.
                WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
                WithExpression(SyntaxFactory.IdentifierName(text)).
                WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:59,代码来源:CreateMachineRewriter.cs


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