namespace qdr.app.studiou.orders2printpack.Extensions
{
public static class StringExt
{
public static string ToQuotedString(this string str)
{
if (str == null)
return string.Empty;
return ToDecoratedString(str, "\"");
}
public static string ToDecoratedString(this string str, string leftDecoration, string rightDecoration)
{
if (str == null)
return string.Empty;
return leftDecoration + str + rightDecoration;
}
public static string ToDecoratedString(this string str, string bothDecoration)
{
if (str == null)
return string.Empty;
return ToDecoratedString(str, bothDecoration, bothDecoration);
}
///
/// Returns a list of all duplicate string items in a collection.
///
/// The source collection to check for duplicates.
/// An IEnumerable containing only the duplicate items.
public static IEnumerable GetDuplicates(this IEnumerable source)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
return source
.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(g => g.Key);
}
}
}