ConnectionState - In

A ConnectionState extension method that insert.

Try it

public static void Main()
{
	using (var conn = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
    {		
		//C# Extension Method: ConnectionState - In
        bool result1 = conn.State.In(ConnectionState.Closed, ConnectionState.Open); // return true;
        bool result2 = conn.State.In(ConnectionState.Open, ConnectionState.Executing); // return false;
        Console.WriteLine(result1);
		Console.WriteLine(result2);
    }
}

View Source
using System.Data;

public static partial class Extensions
{
    /// <summary>
    ///     A ConnectionState extension method that insert.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="values">A variable-length parameters list containing values.</param>
    /// <returns>true if it succeeds, false if it fails.</returns>
    public static bool In(this ConnectionState @this, params ConnectionState[] values)
    {
        return values.IndexOf(@this) != -1;
    }
}