本文整理汇总了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();
}
}