Ejemplo n.º 1
0
        public void InsertAfter(LinkMember node)
        {
            if (this == node)
            {
                return;
            }

            LinkMember after;

            if ((after = NextSibling) is null)
            {
                Parent.Add(node);
            }
            else
            {
                if (IsAncestorOf(node))
                {
                    return;
                }

                Mend(END, after, node);

                node.Parent = Parent;
            }
        }
Ejemplo n.º 2
0
        public void InsertBefore(LinkMember node)
        {
            if (this == node)
            {
                return;
            }
            //Can't insert itself before itself.

            var first = PreviousSibling;

            if (first is null)
            {
                Parent.Prepend(node);
                //If previous sibling is null, we have to perform Parent.Prepend(node)
            }
            else
            {
                if (IsAncestorOf(node))
                {
                    return;
                }
                //IsAncestorOf is checked in a similar way in Parent.Prepend.
                //The check for PreviousSibling being null is quicker than IsAncestorOf
                //so calling IsAncestorOf here is more appropriate than calling first.

                Mend(first.END, this, node);

                node.Parent = Parent;
            }
        }
Ejemplo n.º 3
0
        private void Mend(LinkMember start, LinkMember finish, LinkMember node)
        {
            node.Pop();

            start.SetNext(node);
            node.SetPrev(start);

            finish.SetPrev(node.END);
            node.END.SetNext(finish);
        }
Ejemplo n.º 4
0
        public void Add(LinkMember node)
        {
            if (this == node || IsAncestorOf(node))
            {
                return;
            }

            Mend(END.Prev, END, node);

            node.Parent = this;
        }
Ejemplo n.º 5
0
        public void Prepend(LinkMember node)
        {
            if (this == node || IsAncestorOf(node))
            {
                return;
            }

            Mend(this, Next, node);

            node.Parent = this;
        }
Ejemplo n.º 6
0
        public LinkMember(object value)
        {
            END = new LinkMember()
            {
                Value = "END"
            };

            Value      = value;
            Next       = END;
            END.Prev   = this;
            END.Parent = this;
        }
Ejemplo n.º 7
0
 public void Replace(LinkMember remove, LinkMember insert)
 {
     remove.InsertAfter(insert);
     remove.Pop();
 }
Ejemplo n.º 8
0
 public bool IsAncestorOf(LinkMember linkMember) => GetParents().FirstOrDefault(parent => parent == linkMember) is not null;
Ejemplo n.º 9
0
 public void SetPrev(LinkMember node) => Prev = node;
Ejemplo n.º 10
0
 public void SetNext(LinkMember node) => Next = node;