public static void If(this CodeStatementCollection stmts, CodeExpression condition, Action <CodeStatementCollection> body) { CodeStatementCollection ifTrue = new CodeStatementCollection(); body(ifTrue); stmts.Add(new CodeConditionStatement(condition, ifTrue.Cast <CodeStatement>().ToArray())); }
/// <summary> /// Handles a collection of statements /// </summary> /// <param name="coll"></param> /// <param name="ctx"></param> /// <param name="doBlockAndIndentation">If true will also output indentation and {}</param> public static void HandleStatementCollection(CodeStatementCollection coll, Context ctx, bool doBlockAndIndentation = true, bool endWithNewLine = true) { if (doBlockAndIndentation) { ctx.Writer.NewLine(); ctx.Writer.IndentAndWriteLine("{", ctx); ctx.Indent(); } GeneralUtils.HandleCollection(coll.Cast <CodeStatement>(), ctx.HandlerProvider.StatementHandler, ctx, preAction: (c) => c.Writer.Indent(c), postAction: (c) => c.Writer.NewLine(), doPostActionOnLast: true); if (doBlockAndIndentation) { ctx.Unindent(); ctx.Writer.IndentAndWrite("}", ctx); if (endWithNewLine) { ctx.Writer.NewLine(); } } }
// ReSharper disable once SuggestBaseTypeForParameter private static void HandleStatementCollection(CodeStatementCollection coll, Context ctx, BlockType?blockType, bool endWithNewLine) { if (blockType != null) { BeginBlock((BlockType)blockType, ctx); } GeneralUtils.HandleCollection(coll.Cast <CodeStatement>(), ctx.HandlerProvider.StatementHandler, ctx, preAction: (c) => c.Writer.Indent(c), postAction: (c) => c.Writer.NewLine(), doPostActionOnLast: true); if (blockType != null) { if (endWithNewLine) { EndBlock(ctx); } else { ctx.Unindent(); ctx.Writer.Indent(ctx); EndBlock(ctx, false); } } }