In and NotIn
C# equivalents of two other well-known SQL constructs
///
/// Determines if the source value is contained in the list of possible values.
///
/// The type of the objects
/// The source value
/// The list of possible values
///
/// true if the source value matches at least one of the possible values; otherwise, false.
///
public static bool In(this T value, params T[] values)
{
if (values == null)
return false;
if (values.Contains(value))
return true;
return false;
}
///
/// Determines if the source value is contained in the list of possible values.
///
/// The type of the objects
/// The source value
/// The list of possible values
///
/// true if the source value matches at least one of the possible values; otherwise, false.
///
public static bool In(this T value, IEnumerable values)
{
if (values == null)
return false;
if (values.Contains(value))
return true;
return false;
}
///
/// Determines if the source value is not contained in the list of possible values.
///
/// The type of the objects
/// The source value
/// The list of possible values
///
/// false if the source value matches at least one of the possible values; otherwise, true.
///
public static bool NotIn(this T value, params T[] values)
{
return In(value, values) == false;
}
///
/// Determines if the source value is not contained in the list of possible values.
///
/// The type of the objects
/// The source value
/// The list of possible values
///
/// false if the source value matches at least one of the possible values; otherwise, true.
///
public static bool NotIn(this T value, IEnumerable values)
{
return In(value, values) == false;
}