Skip to content

Commit

Permalink
report violations of 'EnsureNotNull()' as 'NullReferenceException' in…
Browse files Browse the repository at this point in the history
…stead of 'NotSupportedException'
  • Loading branch information
adrianoc committed Apr 3, 2024
1 parent 55c77f3 commit 6b09000
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cecilifier.Core/Extensions/ISymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using Cecilifier.Core.AST;
using Cecilifier.Core.Misc;
using Cecilifier.Core.Naming;
Expand Down Expand Up @@ -80,10 +81,10 @@ public static bool IsByRef(this ISymbol symbol) =>
};

[return: NotNull]
public static T EnsureNotNull<T>([NotNullIfNotNull("symbol")] this T symbol) where T : ISymbol
public static T EnsureNotNull<T>([NotNullIfNotNull("symbol")] this T symbol, [CallerArgumentExpression(nameof(symbol))] string expression = null) where T : ISymbol
{
if (symbol == null)
throw new System.NotSupportedException("");
throw new NullReferenceException($"Expression '{expression}' is expected to not be null.");

return symbol;
}
Expand Down

0 comments on commit 6b09000

Please sign in to comment.