Extension Method - String

using System.Text.RegularExpressions;

namespace Shand.Extension
{
    public static partial class Extensions
    {
        public static bool IsNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str);
        }

        public static bool IsRegexMatch(this string str, string pattern)
        {
            return new Regex(pattern).IsMatch(str);
        }
    }
}


これはみんなやるはず!

string str = "";
if (str.IsNullOrEmpty())
{
    Console.WriteLine("NullOrEmpty");
}


けっこう便利だと思うのだが…

string str = "abc";
if (str.IsRegexMatch("^a"))
{
    Console.WriteLine("Match");
}
else
{
    Console.WriteLine("Not Match");
}