Пример #1
0
        public static LoopExpression Loop(Expression test, Expression increment, Expression body, Expression @else, LabelTarget @break, LabelTarget @continue)
        {
            ContractUtils.RequiresNotNull(body, "body");
            if (test != null)
            {
                ContractUtils.Requires(test.Type == typeof(bool), "test", "Test must be boolean");
                if (@break == null)
                {
                    @break = Expression.Label();
                }
            }

            // for (;;) {
            //     if (test) {
            //     } else {
            //        else;
            //        break;
            //     }
            //     Body
            // continue:
            //     Increment;
            // }

            // If there is no test, 'else' will never execute and gets simply thrown away.
            return(Expression.Loop(
                       Expression.Block(
                           test != null
                        ? (Expression)Expression.Condition(
                               test,
                               Utils.Empty(),
                               Expression.Block(
                                   @else != null ? @else : Utils.Empty(),
                                   Expression.Break(@break)
                                   )
                               )
                        : Utils.Empty(),
                           body,
                           @continue != null ? (Expression)Expression.Label(@continue) : Utils.Empty(),
                           increment != null ? increment : Utils.Empty()
                           ),
                       @break,
                       null
                       ));
        }
Пример #2
0
 public static LoopExpression Infinite(Expression body, LabelTarget @break, LabelTarget @continue)
 {
     return(Expression.Loop(body, @break, @continue));
 }
Пример #3
0
 public static LoopExpression Infinite(Expression body)
 {
     return(Expression.Loop(body, null, null));
 }