using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace JiShe.CollectBus.Common.Extensions { /// /// Extension methods for . /// public static class EnumerableExtensions { /// /// Concatenates the members of a constructed collection of type System.String, using the specified separator between each member. /// This is a shortcut for string.Join(...) /// /// A collection that contains the strings to concatenate. /// The string to use as a separator. separator is included in the returned string only if values has more than one element. /// A string that consists of the members of values delimited by the separator string. If values has no members, the method returns System.String.Empty. [Description("Enumerable转换String")] public static string JoinAsString(this IEnumerable source, string separator) { return string.Join(separator, source); } /// /// Concatenates the members of a collection, using the specified separator between each member. /// This is a shortcut for string.Join(...) /// /// A collection that contains the objects to concatenate. /// The string to use as a separator. separator is included in the returned string only if values has more than one element. /// The type of the members of values. /// A string that consists of the members of values delimited by the separator string. If values has no members, the method returns System.String.Empty. public static string JoinAsString(this IEnumerable source, string separator) { return string.Join(separator, source); } /// /// Filters a by given predicate if given condition is true. /// /// Enumerable to apply filtering /// A boolean value /// Predicate to filter the enumerable /// Filtered or not filtered enumerable based on [Description("Enumerable筛选")] public static IEnumerable WhereIf(this IEnumerable source, bool condition, Func predicate) { return condition ? source.Where(predicate) : source; } /// /// Filters a by given predicate if given condition is true. /// /// Enumerable to apply filtering /// A boolean value /// Predicate to filter the enumerable /// Filtered or not filtered enumerable based on public static IEnumerable WhereIf(this IEnumerable source, bool condition, Func predicate) { return condition ? source.Where(predicate) : source; } } }