Extension method for is string whitespace, null or empty.

Here’s a quick extension method which returns true if string is whitespace, null or empty. I’ve also added

using Microsoft.VisualStudio.TestTools.UnitTesting;

public static class Extensions
{
    public static bool IsWhitespaceNullOrEmpty(this string s)
    {
        if (s == null) return true;
        if (s.Trim() == string.Empty) return true;
        return false;
    }
}

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestStringNull()
    {
        string s = null;
        Assert.IsTrue(s.IsWhitespaceNullOrEmpty());
        Assert.IsTrue(((string)null).IsWhitespaceNullOrEmpty());
    }

    [TestMethod]
    public void TestStringEmpty()
    {
        Assert.IsTrue(string.Empty.IsWhitespaceNullOrEmpty());
    }

    [TestMethod]
    public void TestSpaceStringEmpty()
    {
        Assert.IsTrue("    ".IsWhitespaceNullOrEmpty());
    }

    [TestMethod]
    public void TestTabStringEmpty()
    {
        Assert.IsTrue("\t".IsWhitespaceNullOrEmpty());
    }

    [TestMethod]
    public void TestStringNotEmpty()
    {
        Assert.IsTrue(!"a".IsWhitespaceNullOrEmpty());
    }
}