private static void TryInlineIfThenReturnFollowedByReturn(IfThenElement ifThen, IList<IElement> elements, int index)
        {
            if (index == elements.Count - 1)
                return;

            if (ifThen.Then.Count != 1 || ifThen.Else.Count > 0)
                return;

            var returnInIf = ifThen.Then.Single() as ReturnElement;
            var returnAfterIf = elements[index + 1] as ReturnElement;
            if (returnInIf == null || returnAfterIf == null)
                return;

            if (returnInIf.Result == null || returnAfterIf.Result == null)
                return;

            elements[index] = new ReturnElement(Expression.Condition(
                ifThen.Condition,
                returnInIf.Result,
                returnAfterIf.Result
            ));

            elements.RemoveAt(index + 1);
        }
Beispiel #2
0
 protected virtual IElement VisitReturn(ReturnElement @return)
 {
     @return.Result = this.Visit(@return.Result);
     return(@return);
 }