In C# indicate to static analyzers that a method guarantees non-null values

With .NET 6, it is easy to create helper or extension methods that can throw an exception without dirtying up the stack trace. For example: [System.Diagnostics.StackTraceHidden] public static void ThrowIfNullOrWhitespace(this string? stringValue, Exception exception) { if (string.IsNullOrWhiteSpace(stringValue)) throw exception; } In this case, you can call that method foo.ThrowIfNullOrWhitespace(new ArgumentException("null or whitespace")); but subsequent uses… Read More In C# indicate to static analyzers that a method guarantees non-null values