예제 #1
0
        /// <summary>
        /// Handle a collection with the provided handler.
        /// <para/>
        /// Will execute <paramref name="preAction"/> before every handling
        /// <para/>
        /// Will execute <paramref name="postAction"/> after every handling apart from the last one unless
        /// <paramref name="doPostActionOnLast"/> is true
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="handler"></param>
        /// <param name="ctx"></param>
        /// <param name="preAction"></param>
        /// <param name="postAction"></param>
        /// <param name="doPostActionOnLast"></param>
        /// <typeparam name="T"></typeparam>
        public static void HandleCollection <T>(IEnumerable <T> coll, ICodeObjectHandler <T> handler, Context ctx,
                                                Action <Context> preAction = null, Action <Context> postAction = null, bool doPostActionOnLast = true)
        {
            using (var enumerator = coll.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    return;
                }

                preAction?.Invoke(ctx);
                handler.Handle(enumerator.Current, ctx);
                while (enumerator.MoveNext())
                {
                    postAction?.Invoke(ctx);
                    preAction?.Invoke(ctx);
                    handler.Handle(enumerator.Current, ctx);
                }

                if (doPostActionOnLast)
                {
                    postAction?.Invoke(ctx);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Handles a collection with the provided handler, handling each object on a single line mantaining the current
 /// level of indentation, ending with a new line.
 /// </summary>
 /// <param name="coll"></param>
 /// <param name="handler"></param>
 /// <param name="ctx"></param>
 /// <param name="doIndentAsPreAction">If it is set to true line indentation is handled as pre-action,
 /// otherwise it is done as postaction, after the newline</param>
 /// <typeparam name="T"></typeparam>
 public static void HandleCollectionOnMultipleLines <T>(IEnumerable <T> coll, ICodeObjectHandler <T> handler,
                                                        Context ctx, bool doIndentAsPreAction)
 {
     HandleCollection(coll, handler, ctx,
                      preAction: doIndentAsPreAction ? (c) => { c.Writer.Indent(c); } : (Action <Context>)null,
                      postAction: doIndentAsPreAction ? (c) => { c.Writer.NewLine(); }
             : (Action <Context>)((c) =>
     {
         c.Writer.NewLine();
         c.Writer.Indent(c);
     }), doPostActionOnLast: true);
 }
 /// <summary>
 /// Add the provided handler to this compileUnitHandler
 /// </summary>
 /// <param name="handler"></param>
 public void AddCompileUnitHandler(ICodeObjectHandler <CodeCompileUnit> handler)
 {
     _compileUnitHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="ExpressionHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddExpressionHandler(ICodeObjectHandler <CodeExpression> handler)
 {
     _expressionHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="DirectiveHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddDirectiveHandler(ICodeObjectHandler <CodeDirective> handler)
 {
     _directiveHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="CommentHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddCommentHandler(ICodeObjectHandler <CodeComment> handler)
 {
     _commentHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="AttributeDeclarationHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddAttributeDeclarationHandler(ICodeObjectHandler <CodeAttributeDeclaration> handler)
 {
     _attributeDeclarationHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="OtherObjectHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddOtherObjectHandler(ICodeObjectHandler <object> handler)
 {
     _otherObjectHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="StatementHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddStatementHandler(ICodeObjectHandler <CodeStatement> handler)
 {
     _statementHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="TypeParameterHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddTypeParameterHandler(ICodeObjectHandler <CodeTypeParameter> handler)
 {
     _typeParameterHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="TypeReferenceHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddTypeReferenceHandler(ICodeObjectHandler <CodeTypeReference> handler)
 {
     _typeReferenceHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="TypeDeclarationHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddTypeDeclarationHandler(ICodeObjectHandler <CodeTypeDeclaration> handler)
 {
     _typeDeclarationHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add an handler, which will be used by <see cref="Handle"/> method
 /// </summary>
 /// <param name="handler"></param>
 public void AddHandler(ICodeObjectHandler <T> handler)
 {
     _handlers.Add(handler);
 }
예제 #14
0
 /// <summary>
 /// Handles a collection with the provided handler, separating each handling with a ", "
 /// </summary>
 /// <param name="coll"></param>
 /// <param name="handler"></param>
 /// <param name="ctx"></param>
 /// <typeparam name="T"></typeparam>
 public static void HandleCollectionCommaSeparated <T>(IEnumerable <T> coll, ICodeObjectHandler <T> handler,
                                                       Context ctx)
 {
     HandleCollection(coll, handler, ctx, postAction: (c) => c.Writer.Write(", "), doPostActionOnLast: false);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="MemberAttributesHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddMemberAttributesHandler(ICodeObjectHandler <MemberAttributes> handler)
 {
     _memberAttributesHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="TypeAttributesHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddTypeAttributesHandler(ICodeObjectHandler <TypeAttributes> handler)
 {
     _typeAttributesHandler.AddHandler(handler);
 }
 /// <summary>
 /// Add the provided handler to this <see cref="NamespaceHandler"/>
 /// </summary>
 /// <param name="handler"></param>
 public void AddNamespaceHandler(ICodeObjectHandler <CodeNamespace> handler)
 {
     _namespaceHandler.AddHandler(handler);
 }