using System.Runtime.CompilerServices; namespace System.Core.Extensions; public static class ObjectExtensions { public static T ThrowIfNull([ValidatedNotNull] this T obj, [CallerArgumentExpression("obj")] string? paramName = null) where T : class { if (obj is null) { throw new ArgumentNullException(paramName); } return obj; } [AttributeUsage(AttributeTargets.Parameter)] sealed class ValidatedNotNullAttribute : Attribute { } }