internal static void Clear(TList list)
            {
                if (list == null)
                {
                    throw new ArgumentNullException("list");
                }
                list.InvokeInMonitorLock(() =>
                {
                    if (list._firstNode == null)
                    {
                        return;
                    }

                    WithAll(list.GetInChange(() =>
                    {
                        var r = list.Select((node, index) =>
                        {
                            RaiseRemovingItem(list, node, index);
                            return(new { Item = node, Index = index });
                        }).ToArray();
                        list._firstNode = list._lastNode = null;
                        list.Count      = 0L;
                        foreach (var i in r)
                        {
                            i.Item._nextNode  = null;
                            i.Item._container = null;
                        }
                        return(r);
                    }), a => RaiseItemRemoved(list, a.Item, a.Index));
                });
            }
 internal static void Add(TList list, TElement item)
 {
     if (list == null)
     {
         throw new ArgumentNullException("list");
     }
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     list.InvokeInMonitorLock(() => RaiseItemAdded(list, item, item.GetInMonitorLock(() =>
     {
         ValidateItemOrphaned(list, item);
         return(list.GetInChange(() =>
         {
             long i = list.Count;
             RaiseAddingItem(list, item, i);
             if (list._firstNode == null)
             {
                 list._firstNode = list._lastNode = item;
                 list.Count = 1;
             }
             else
             {
                 list._lastNode._nextNode = item;
                 list._lastNode = item;
                 list.Count++;
             }
             item._container = list;
             return i;
         }));
     })));
 }