/// <summary> /// Ases the matrix list. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="list">The list.</param> /// <param name="key">The key.</param> /// <param name="keyCaseSensitive">if set to <c>true</c> [key case sensitive].</param> /// <returns>MatrixList<T>.</returns> public static MatrixList <T> AsMatrixList <T>(this List <T> list, string key, bool keyCaseSensitive = true) { var result = new MatrixList <T>(keyCaseSensitive) { { key.SafeToString(), list ?? new List <T>() } }; 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. /// </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 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); }
/// <summary> /// To the list. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="matrixList">The matrix list.</param> /// <param name="filter">The filter.</param> /// <returns>List<T>.</returns> public static List <T> ToList <T>(this MatrixList <T> matrixList, Func <string, T, bool> filter = null) { List <T> result = new List <T>(); if (matrixList != null) { foreach (var one in matrixList) { foreach (var item in one.Value) { if (filter == null || filter(one.Key, item)) { result.Add(item); } } } } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="MatrixList{T}"/> class. /// </summary> /// <param name="matrixList">The matrix list.</param> /// <param name="keyCaseSensitive">if set to <c>true</c> [key case sensitive].</param> public MatrixList(MatrixList <T> matrixList, bool keyCaseSensitive) : base(matrixList, keyCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase) { }
/// <summary> /// Initializes a new instance of the <see cref="MatrixList{T}" /> class. /// </summary> /// <param name="matrixList">The matrix list.</param> public MatrixList(MatrixList <T> matrixList) : base(matrixList) { }