Handy Extension Methods






2.83/5 (3 votes)
Here are a couple of my favorite extension methhods. What are yours?
using System.Collections.Generic;
using System.Text.RegularExpressions;
public static class ExtensionMethods
{
/// <summary>
/// Add a sequence to a collection.
/// </summary>
/// <typeparam name="T">Object type.</typeparam>
/// <param name="coll">Generic collection.</param>
/// <param name="seq">Generic sequence.</param>
public static void Add<T>(this ICollection<T> coll, IEnumerable<T> seq)
{
foreach (T item in seq)
coll.Add(item);
}
/// <summary>
/// Indicates whether the specified string is null, empty, or whitespace.
/// </summary>
/// <param name="value">The string to test.</param>
/// <returns>Value indicating whether string contains squat.</returns>
public static bool IsNullEmptyOrWhitespace(this string value)
{
return string.IsNullOrEmpty(value) || !Regex.IsMatch(value, @"\S");
}
}