public virtual void AfterVisit(SwitchStatement node) { this.AfterVisitCatchAll(node); }
public virtual void BeforeVisit(SwitchStatement node) { this.BeforeVisitCatchAll(node); }
public override void AfterVisit(SwitchStatement node) { //In the case of a switch statement with no cases, the default block always executes and the expression should be evaluated too, in case there are side effects. //Note: Can't pass an empty cases collection to Expression.Switch() - an ArgumentException will result. if (node.Cases.Length == 0) { var notSwitchExprs = new List<Expression>(); if (node.DefaultStatementBlock != null) notSwitchExprs.Add(_expressionStack.Pop()); notSwitchExprs.Add(_expressionStack.Pop()); _expressionStack.Push(node, MaybeBlock(notSwitchExprs)); return; } Expression defaultBlock = null; if (node.DefaultStatementBlock != null) defaultBlock = _expressionStack.Pop(); var cases = _expressionStack.Pop(node.Cases.Length, false).Cast<ContainerPseudoExpression<System.Linq.Expressions.SwitchCase>>().Select(container => container.ContainedItem).ToList(); var switchExpr = _expressionStack.Pop(); MethodInfo comparerMethodInfo = typeof(RuntimeHelpers).GetMethod("HappyEq"); _expressionStack.Push(node, Expression.Switch(switchExpr, defaultBlock, comparerMethodInfo, cases)); base.AfterVisit(node); }