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


C# InvocationExpressionSyntax.GetReferencedSymbol方法代码示例

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


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

示例1: VisitInvocationExpression

		/// <summary>
		///     Adds omitted optional arguments to the <paramref name="invocation" />.
		/// </summary>
		public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
		{
			// Nothing to do if the method doesn't declare any optional parameters
			var methodSymbol = invocation.GetReferencedSymbol<IMethodSymbol>(SemanticModel);
			if (methodSymbol.Parameters.All(parameter => !parameter.IsOptional))
				return base.VisitInvocationExpression(invocation);

			// Nothing to do if all optional arguments have been provided
			if (invocation.ArgumentList.Arguments.Count == methodSymbol.Parameters.Length)
				return base.VisitInvocationExpression(invocation);

			// Determine the optional parameters that the invocation omits
			var omittedParameters = new HashSet<IParameterSymbol>(methodSymbol.Parameters);
			omittedParameters.ExceptWith(invocation.ArgumentList.Arguments.Select(argument => argument.GetParameterSymbol(SemanticModel)));

			// Recursively normalize the arguments of the invocation
			invocation = (InvocationExpressionSyntax)base.VisitInvocationExpression(invocation);
			var arguments = invocation.ArgumentList.Arguments;

			// Add the default values of all omitted optional arguments as named arguments to the end of the argument list;
			// we can safely ignore param arrays here
			foreach (var omittedParameter in omittedParameters.Where(omittedParameter => !omittedParameter.IsParams))
			{
				Assert.That(omittedParameter.HasExplicitDefaultValue, "Expected an implicit default value.");
				Assert.That(omittedParameter.RefKind == RefKind.None, "Optional parameter cannot be ref or out.");

				// Determine the default value; only structs, decimal, int, and bool are supported
				var defaultValue = String.Empty;
				var value = omittedParameter.ExplicitDefaultValue;
				if (value == null)
					defaultValue = String.Format("default({0})", omittedParameter.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
				else if (value is decimal)
					defaultValue = ((decimal)value).ToString(CultureInfo.InvariantCulture) + "m";
				else if (value is int)
					defaultValue = ((int)value).ToString(CultureInfo.InvariantCulture);
				else if (value is bool)
					defaultValue = ((bool)omittedParameter.ExplicitDefaultValue) ? "true" : "false";

				var argument = SyntaxFactory.Argument(SyntaxFactory.NameColon(omittedParameter.Name),
					SyntaxFactory.Token(SyntaxKind.None), SyntaxFactory.ParseExpression(defaultValue));

				arguments = arguments.Add(argument);
			}

			return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(arguments)).NormalizeWhitespace();
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:49,代码来源:OptionalArgumentNormalizer.cs

示例2: DecomposeTransitionChain

		/// <summary>
		///   Collects all calls to <see cref="StateMachine{TState}" /> <c>Transition</c> methods within
		///   <paramref name="expression" />.
		/// </summary>
		private List<Transition> DecomposeTransitionChain(InvocationExpressionSyntax expression, out ExpressionSyntax stateMachine)
		{
			var transitions = new List<Transition>();

			while (true)
			{
				AddTransitions(transitions, expression.ArgumentList);

				var memberAccess = (MemberAccessExpressionSyntax)expression.Expression;
				if (memberAccess.Expression.Kind() != SyntaxKind.InvocationExpression)
				{
					stateMachine = memberAccess.Expression;
					break;
				}

				expression = (InvocationExpressionSyntax)memberAccess.Expression;
				var methodSymbol = expression.GetReferencedSymbol<IMethodSymbol>(SemanticModel);
				if (!methodSymbol.IsTransitionMethod(SemanticModel))
				{
					stateMachine = expression;
					break;
				}
			}

			transitions.Reverse();
			return transitions;
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:31,代码来源:TransitionNormalizer.cs


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