I spent more than 2 days get these. Hope it help your code shorter
especially in lambda expression.
It works for both structure and reference types.
1 public static bool IsItemOfCollection<T, TCollection>(this T thisT, TCollection collection) where TCollection : ICollection<T> 2 { 3 return collection.Contains(thisT); 4 } 5 6 public static bool Greater<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T> 7 { 8 return thisT.CompareTo(obj) > 0; 9 } 10 11 public static bool Less<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T> 12 { 13 return thisT.CompareTo(obj) < 0; 14 } 15 16 public static bool GreaterThan<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T> 17 { 18 return thisT.CompareTo(obj) >= 0; 19 } 20 21 public static bool LessThan<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T> 22 { 23 return thisT.CompareTo(obj) <= 0; 24 } 25 26 public static bool NotEquals<T>(this T thisT, T obj) where T : IComparable<T>, IEquatable<T> 27 { 28 return !thisT.Equals(obj); 29 }
