| | | 1 | | namespace ArturRios.Extensions; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Provides comparison helpers and syntactic sugar for checking membership (In/NotIn). |
| | | 5 | | /// </summary> |
| | | 6 | | public static class ComparisonExtensions |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Provides comparison helpers for the given value. |
| | | 10 | | /// </summary> |
| | | 11 | | extension<T>(T self) |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Returns true if the value is equal to any element in the provided range. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="range">Values to compare against.</param> |
| | | 17 | | /// <returns>True if a match is found; otherwise false.</returns> |
| | 20 | 18 | | public bool In(params T[] range) => range.Any(t => t?.Equals(self) ?? self == null); |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Returns true if the value is not equal to any element in the provided range. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="range">Values to compare against.</param> |
| | | 24 | | /// <returns>True if no match is found; otherwise false.</returns> |
| | 2 | 25 | | public bool NotIn(params T[] range) => !self.In(range); |
| | | 26 | | } |
| | | 27 | | } |