public static class Extensions
public static T ThrowIf<T, TException>(this T instance, Func<T, bool> check, Func<TException> exceptionFactory) where TException : Exception => !check(instance) ? instance : throw exceptionFactory();
public static void Main()
number.ThrowIf(n => n < 0, () => new ArgumentException("Number cannot be negative"));