public static IDrawer[] CreateAndDisposeList(ref List <IDrawer> list) { var result = Create(list); DrawerListPool.Dispose(ref list); return(result); }
public static void ListToArrayAndDispose(ref List <IDrawer> list, ref IDrawer[] array, bool disposeArrayContent) { if (array == null) { array = Create(list); } else { int size = list.Count; if (array.Length == size) { if (disposeArrayContent) { for (int n = size - 1; n >= 0; n--) { var existing = array[n]; if (existing != null) { existing.Dispose(); } array[n] = list[n]; } } else { for (int n = size - 1; n >= 0; n--) { array[n] = list[n]; } } } else { Dispose(ref array, disposeArrayContent); array = Create(list); } } DrawerListPool.Dispose(ref list); }