using System.Runtime.CompilerServices;
catch (InvalidOperationException e)
Console.WriteLine(e.Message);
catch (InvalidOperationException e)
Console.WriteLine(e.Message);
public static class NullableExtensions
public static T ThrowIfNull<T>(
this T? input, [CallerArgumentExpression("input")] string? description = null)
input ?? ThrowMustNotBeNull<T>(description);
public static T ThrowIfNull<T>(
this T? input, [CallerArgumentExpression("input")] string? description = null)
input ?? ThrowMustNotBeNull<T>(description);
private static T ThrowMustNotBeNull<T>(string? description) =>
throw new InvalidOperationException($"{description} must not be null");