using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PlixP.Extentions { public static class Assert { public static void NotNull(T obj, string name, string message = null) where T : class { if (obj is null) throw new ArgumentNullException($"{name} : {typeof(T)}", message); } public static void NotNull(T? obj, string name, string message = null) where T : struct { if (!obj.HasValue) throw new ArgumentNullException($"{name} : {typeof(T)}", message); } public static void NotEmpty(T obj, string name, string message = null, T defaultValue = null) where T : class { if (obj == defaultValue || (obj is string str && string.IsNullOrWhiteSpace(str)) || (obj is IEnumerable list && !list.Cast().Any())) { throw new ArgumentException("Argument is empty : " + message, $"{name} : {typeof(T)}"); } } } }