/// <inheritdoc/> int IList.Add(object value) { if (value is T t) { using (Lock.WriteUsing()) { int index = Backing.Count; Backing.Add(t); return(index); } } return(-1); }
/// <summary> /// Sorts the list using the given selector and comparer./> /// </summary> public void Sort <TKey>(Func <T, TKey> selector, IComparer <TKey> comparer = null) { using (DeferredUpdate()) using (Lock.WriteUsing()) { comparer = comparer ?? Comparer <TKey> .Default; if (Backing is List <T> lst) { lst.Sort(new TransformComparer <T, TKey>(selector, comparer)); } else { List <T> sortedItems = Backing.OrderBy(selector, comparer).ToList(); Backing.Clear(); foreach (T v in sortedItems) { Backing.Add(v); } } } }