Beispiel #1
0
        [BlueprintRule_MethodAliasDef(MirrorClass = typeof(List_String))]   // This implies the name and parameters stay the same
        public IList <string> Unique(IList <string> list, enCompare_Sort sortType = enCompare_Sort.NoSort, bool ignoreCase = false)
        {
            if (list == null)
            {
                return(null);                // throw new ArgumentNullException(nameof(list));
            }
            var comparer = (ignoreCase) ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
            var result   = list.Distinct(comparer).ToList();

            return(Sort(result, sortType));
        }
Beispiel #2
0
        /// <summary>Sorts the specified list.</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">The list.</param>
        /// <param name="sort">if set to <c>true</c> [acending].</param>
        /// <returns></returns>
        public IList <T> Sort <T>(IList <T> list, enCompare_Sort sort = enCompare_Sort.Ascending)
        {
            switch (sort)
            {
            case enCompare_Sort.Ascending: return(list.OrderBy(q => q).ToList());

            case enCompare_Sort.Descending: return(list.OrderByDescending(q => q).ToList());

            case enCompare_Sort.NoSort: return(list);

            default: throw new Exception($"Argument '{nameof(sort)}' error.");
            }
            return(list);
        }
Beispiel #3
0
        /// <summary>
        /// Sorts the by length.
        /// </summary>
        /// <param name="array">The array</param>
        /// <param name="sortType">Acending indicator. Default value = true.</param>
        /// <returns>IEnumerable<string/></returns>
        public IEnumerable <string> SortByStrLength(IEnumerable <string> array, enCompare_Sort sortType = enCompare_Sort.Ascending)
        {
            // Use LINQ to sortType the array received and return a copy.

            if (sortType == enCompare_Sort.Ascending)
            {
                var sorted = array.OrderBy(str => str.Length).ToArray();
                return(sorted);
            }
            else if (sortType == enCompare_Sort.Descending)
            {
                var sorted = array.OrderByDescending(str => str.Length).ToArray();
                return(sorted);
            }
            return(array);
        }
Beispiel #4
0
 public IList <string> Unique(IList <string> list, enCompare_Sort sortType = enCompare_Sort.NoSort, bool ignoreCase = false)
 {
     return(_lamed.Types.List.Action.Unique(list, sortType, ignoreCase));
 }
 /// <summary>
 /// String sorts the by length.
 /// </summary>
 /// <param name="array">The ienumerable&lt;string&gt;</param>
 /// <param name="sortType">sortType indicator. Default value = true.</param>
 /// <returns>IEnumerable<string/></returns>
 public static IEnumerable <string> zArray_SortByLength(this IEnumerable <string> array, enCompare_Sort sortType = enCompare_Sort.Ascending)
 {
     return(LamedalCore_.Instance.Types.List.String.SortByStrLength(array, sortType));
 }