/// <summary> /// Return the enumerable as a List of T, copying if required. Optimized for common case where it is an List of T /// or a ListWrapperCollection of T. Avoid mutating the return value. /// </summary> public static List <T> AsList <T>(this IEnumerable <T> target) { Contract.Assert(target != null); List <T> list = target as List <T>; if (list != null) { return(list); } ListWrapperCollection <T> listWrapper = target as ListWrapperCollection <T>; if (listWrapper != null) { return(listWrapper.ItemsList); } return(new List <T>(target)); }
/// <summary> /// Return the enumerable as a List of T, copying if required. Optimized for common case where it is an List of T /// or a ListWrapperCollection of T. Avoid mutating the return value. /// </summary> public static List <T> AsList <T>(this IEnumerable <T> enumerable) { Contract.Assert(enumerable != null); List <T> list = enumerable as List <T>; if (list != null) { return(list); } ListWrapperCollection <T> listWrapper = enumerable as ListWrapperCollection <T>; if (listWrapper != null) { return(listWrapper.ItemsList); } return(new List <T>(enumerable)); }