Archive for February, 2012

C# Extension for In-operator substitute

Saturday, February 25th, 2012
public static class Extensions
{
  public static bool In(this T actualvalue, params T[] possiblevalues)
  {
    return (new List(possiblevalues)).Contains(actualvalue);
  }

  public static bool In(this T actualvalue, IEnumerable possiblevalues)
  {
    return (new List(possiblevalues)).Contains(actualvalue);
  }

  public static bool In(this string actualvalue, StringComparison comparison,
    params string[] possiblevalues)
  {
    return possiblevalues.Any(s => string.Equals(s, actualvalue, comparison));
  }

  public static bool In(this string actualvalue, StringComparison comparison,
    IEnumerable possiblevalues)
  {
    return possiblevalues.Any(s => string.Equals(s, actualvalue, comparison));
  }
}

Thank you, Whitney

Sunday, February 12th, 2012

:-(