/// <summary> /// To the matrix. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list">The list.</param> /// <param name="keyFunc">The key function.</param> /// <param name="keyCaseSensitive">if set to <c>true</c> [key case sensitive].</param> /// <returns>MatrixList<T>.</returns> public static MatrixList <T> ToMatrix <T>(this List <T> list, Func <T, string> keyFunc, bool keyCaseSensitive = true) { var result = new MatrixList <T>(keyCaseSensitive); if (list != null && keyFunc != null) { foreach (var one in list) { result.Add(keyFunc(one), one); } } return(result); }
/// <summary> /// To the matrix. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam> /// <param name="list">The list.</param> /// <param name="keyFunc">The key function.</param> /// <param name="valueFunc">The value function.</param> /// <param name="equalityComparer">The equality comparer.</param> /// <returns></returns> public static MatrixList <TKey, TValue> ToMatrix <TEntity, TKey, TValue>(this List <TEntity> list, Func <TEntity, TKey> keyFunc, Func <TEntity, TValue> valueFunc, IEqualityComparer <TKey> equalityComparer = null) { var result = new MatrixList <TKey, TValue>(equalityComparer); if (list != null && keyFunc != null && valueFunc != null) { foreach (var one in list) { result.Add(keyFunc(one), valueFunc(one)); } } return(result); }
/// <summary> /// To the matrix list. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <typeparam name="TSource">The type of the source.</typeparam> /// <param name="source">The source.</param> /// <param name="comparer">The comparer.</param> /// <returns></returns> public static MatrixList <TKey, TSource> ToMatrixList <TKey, TSource>(this IEnumerable <IGrouping <TKey, TSource> > source, IEqualityComparer <TKey> comparer = null) { MatrixList <TKey, TSource> result = new MatrixList <TKey, TSource>(comparer); if (source.HasItem()) { foreach (var item in source) { result.Add(item.Key, (item as IEnumerable <TSource>).ToList() ?? new List <TSource>()); } } return(result); }