private void DoInsertNextRecursion(ref THandler target, ref THandler next, XPipelineContext <THandler> current) { if (current.Handler == target) { var next_context = new XPipelineContext <THandler>(next); var origin_next = current.Next; current.Next = next_context; next_context.Prev = current; next_context.Next = origin_next; if (origin_next != null) { origin_next.Prev = next_context; } if (_last == current) { _last = next_context; } } else if (current.Next != null) { DoInsertNextRecursion(ref target, ref next, current.Next); } }
/// <summary> /// 倒序 (TENET o((>ω< ))o /// </summary> /// <param name="context"></param> /// <param name="callback"></param> private void DoPipelineReverse(XPipelineContext <THandler> context, Func <THandler, bool> callback) { if (context != null && context.Handler != null) { bool doNext = callback(context.Handler); if (doNext && context.Prev != null && context.Prev != context) { DoPipelineReverse(context.Prev, callback); } } }
private void DoPipeline(XPipelineContext <THandler> context, Func <THandler, THandler, bool> callback) { if (context != null && context.Handler != null) { bool doNext = callback(context.Handler, context.Next == null ? default : context.Next.Handler); if (doNext && context.Next != null && context.Next != context) { DoPipeline(context.Next, callback); } } }
private async Task DoPipelineAsync(XPipelineContext <THandler> context, Func <THandler, THandler, Task <bool> > callback) { if (context != null && context.Handler != null) { bool doNext = await callback(context.Handler, context.Next == null?default: context.Next.Handler); if (doNext && context.Next != null && context.Next != context) { await DoPipelineAsync(context.Next, callback); } } }
public XPipelineContext <THandler> AddLast(THandler handler) { var context = new XPipelineContext <THandler>(handler); var origin_prev = _last; _last = context; if (origin_prev != null) { origin_prev.Next = context; context.Prev = origin_prev; } if (_head == null) { _head = origin_prev != null ? origin_prev : _last; } return(context); }
public XPipelineContext <THandler> AddFirst(THandler handler) { var context = new XPipelineContext <THandler>(handler); var _origin_first = _head; context.Next = _origin_first; _head = context; if (_origin_first != null) { _origin_first.Prev = _head; if (_last == null) { _last = _origin_first; } } else { if (_last == null) { _last = context; } } return(context); }
public XPipelineContext(IPipelineHandler <THandler> handler) { _handler = handler; Next = null; Prev = null; }