namespace ASC.Api.Utils; public static class Validate { public static T If(this T item, Func @if, Func then) where T : class { return @if(item) ? then() : item; } public static T IfNull(this T item, Func func) where T : class { return item.If((x) => x == default(T), func); } public static T ThrowIfNull(this T item, Exception e) where T : class { return item.IfNull(() => { throw e; }); } public static T NotFoundIfNull(this T item) where T : class { return NotFoundIfNull(item, "Item not found"); } public static T NotFoundIfNull(this T item, string message) where T : class { return item.IfNull(() => { throw new ItemNotFoundException(message); }); } public static T? NullIfDefault(this T item) where T : struct { return EqualityComparer.Default.Equals(item, default(T)) ? default(T?) : item; } }