C# Extension for In-operator substitute

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));
  }
}

Leave a Reply

You must be logged in to post a comment.