using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SteamTool.Core.Common { public static class EnumerableEx { [Obsolete("", true)] public static IEnumerable Return(TResult value) { yield return value; } public static IEnumerable Distinct(this IEnumerable source, Func keySelector) { var set = new HashSet(EqualityComparer.Default); foreach (var item in source) { var key = keySelector(item); if (set.Add(key)) yield return item; } } public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) { HashSet seenKeys = new HashSet(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } /// /// コレクションを展開し、メンバーの文字列表現を指定した区切り文字で連結した文字列を返します。 /// /// コレクションに含まれる任意の型。 /// 対象のコレクション。 /// セパレーターとして使用する文字列。 /// コレクションの文字列表現を展開し、指定したセパレーターで連結した文字列。 public static string ToString(this IEnumerable source, string separator) { return string.Join(separator, source); } /// /// シーケンスが null でなく、1 つ以上の要素を含んでいるかどうかを確認します。 /// public static bool HasItems(this IEnumerable source) { return source != null && source.Any(); } } }