private static WidgetNode LinkWidgetNodeToList(WidgetNode list, WidgetNode node)
 {
     if (list == null || WidgetNode.Before(node, list))
     {
         if (list != null)
         {
             list.Prev = node;
         }
         node.Next = list;
         return(node);
     }
     else
     {
         var n = list;
         for (; n.Next != null && WidgetNode.Before(n.Next, node); n = n.Next)
         {
             ;
         }
         node.Prev = n;
         node.Next = n.Next;
         if (n.Next != null)
         {
             n.Next.Prev = node;
         }
         n.Next = node;
         return(list);
     }
 }
 private static WidgetNode AdjustWidgetNodePosInList(WidgetNode list, WidgetNode node)
 {
     if ((node.Prev != null && WidgetNode.Before(node, node.Prev)) ||
         (node.Next != null && WidgetNode.Before(node.Next, node)))
     {
         list = UnlinkWidgetNodeFromList(list, node);
         list = LinkWidgetNodeToList(list, node);
     }
     return(list);
 }