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


C# ExpressionSyntax.GetReferencedSymbol方法代码示例

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


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

示例1: TransformExpression

		/// <summary>
		///   Normalizes the <paramref name="expression" />.
		/// </summary>
		private StatementSyntax TransformExpression(ExpressionSyntax expression)
		{
			// If the expression statement is a sequence of 
			// invocation expressions of StateMachine.Transition() ->
			// member access expressions ->
			// invocation expressions StateMachine.Transition() -> 
			// member access expressions -> 
			// ... -> 
			// some other expression of type StateMachine
			// we have to replace all of that by the generated transition code

			if (expression.Kind() != SyntaxKind.InvocationExpression)
				return null;

			var methodSymbol = expression.GetReferencedSymbol<IMethodSymbol>(SemanticModel);
			if (!methodSymbol.IsTransitionMethod(SemanticModel))
				return null;

			try
			{
				_variablePrefixes.Push(Guid.NewGuid().ToString().Replace("-", "_"));

				ExpressionSyntax stateMachine;
				var transitions = DecomposeTransitionChain((InvocationExpressionSyntax)expression, out stateMachine);

				_writer.Clear();
				_writer.AppendLine("#line hidden");
				_writer.AppendLine("unsafe");
				_writer.AppendBlockStatement(() =>
				{
					_writer.AppendLine($"#line {stateMachine.GetLineNumber()}");
					_writer.AppendLine($"var {StateMachineVariable} = {stateMachine.RemoveTrivia().ToFullString()};");
					_writer.AppendLine("#line hidden");
					_writer.AppendLine($"var {ChoiceVariable} = {_helpersType}.GetChoice({StateMachineVariable});");
					_writer.NewLine();

					_writer.AppendLine($"var {TransitionsVariable} = stackalloc int[{transitions.Count}];");
					_writer.AppendLine($"var {CountVariable} = 0;");
					_writer.NewLine();

					GenerateTransitionSelection(transitions);

					_writer.AppendLine($"if ({CountVariable} != 0)");
					_writer.AppendBlockStatement(() =>
					{
						_writer.AppendLine($"switch ({TransitionsVariable}[{ChoiceVariable}.ChooseIndex({CountVariable})])");
						_writer.AppendBlockStatement(() => GenerateTransitionSections(transitions));
					});
				});

				return SyntaxFactory.ParseStatement(_writer.ToString()).WithLeadingNewLines(1);
			}
			finally
			{
				_variablePrefixes.Pop();
			}
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:60,代码来源:TransitionNormalizer.cs


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