private LinkedBuilderContext SwapParent(LinkedBuilderContext newParent) { if (this.parent == null) this.parser.DropContext(this); else this.parent.childs.Remove(this); this.parent = newParent; newParent.Add(this); return newParent; }
private LinkedListNode<LinkedBuilderContext> AddByCommand(InsertCommand command, LinkedBuilderContext context) { return command == InsertCommand.First ? this.childs.AddFirst(context) : this.childs.AddLast(context); }
private LinkedListNode<LinkedBuilderContext> AddByNode(LinkedListNode<LinkedBuilderContext> node, LinkedBuilderContext context) { return this.childs.AddAfter(node, context); }
public INodeBuilderContext WrapContext(INodeBuilder wrapper) { this.TranslateOut(); var preParent = this.parser.ActiveContext; var wrapperContext = new LinkedBuilderContext(parser, preParent, wrapper); preParent.Add(wrapperContext); return this.SwapParent(wrapperContext); }
private LinkedBuilderContext Add(LinkedBuilderContext context) { this.preSiblingPointer = this.insertCommand.HasValue ? this.AddByCommand(this.insertCommand.Value, context) : this.AddByNode(preSiblingPointer, context); return context; }
public INodeBuilderContext ChildContext(INodeBuilder child) { var context = new LinkedBuilderContext(parser, this, child); this.parser.SetActiveContext(context); return this.Add(context); }
public INodeBuilderContext SiblingContext(INodeBuilder sibling) { var context = new LinkedBuilderContext(parser, this.parent, sibling); if (this.parent != null) this.parent.Add(context); else this.parser.AddActiveContext(context); return context; }
public LinkedBuilderContext(NodeTreeParser parser, LinkedBuilderContext parent, INodeBuilder builder) { this.parser = parser; this.parent = parent; this.builder = builder; this.childs = new LinkedList<LinkedBuilderContext>(); this.insertCommand = InsertCommand.Last; this.contextId = _lastId++; }
internal void SetActiveContext(LinkedBuilderContext context, bool contextless) { this.activeContext = context ?? (contextless ? this.AddNewContext() : this.NewContext()); }
internal void SetActiveContext(LinkedBuilderContext context) { SetActiveContext(context, false); }
internal void DropContext(LinkedBuilderContext context) { this.contexts.Remove(context); }
internal void AddActiveContext(LinkedBuilderContext context) { lock (contexts) { this.SetActiveContext(context); this.contexts.Add(activeContext); } }