Skip to content

Commit 85a4a54

Browse files
committed
Address PR feedback
1 parent 0e1ba77 commit 85a4a54

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/UseExceptionThrowHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ aooreThrowIfGreaterThan is not null || aooreThrowIfGreaterThanOrEqual is not nul
181181
{
182182
if (aneThrowIfNull is not null &&
183183
IsParameterNullCheck(condition.Condition, out IParameterReferenceOperation? nullCheckParameter) &&
184-
nullCheckParameter.Type.TypeKind == TypeKind.Class)
184+
nullCheckParameter.Type.IsReferenceType)
185185
{
186186
context.ReportDiagnostic(condition.CreateDiagnostic(
187187
UseArgumentNullExceptionThrowIfNullRule,

src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/Runtime/UseExceptionThrowHelpersTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,21 @@ void GenericMethod<T>(T arg)
187187
{
188188
if (arg is null) throw new ArgumentNullException(nameof(arg));
189189
}
190+
191+
void GenericMethodWithClassConstraint<T>(T arg) where T : class
192+
{
193+
{|CA1510:if (arg is null) throw new ArgumentNullException(nameof(arg));|}
194+
}
195+
196+
void GenericMethodWithTypeConstraint<T>(T arg) where T : C
197+
{
198+
{|CA1510:if (arg is null) throw new ArgumentNullException(nameof(arg));|}
199+
}
200+
201+
void GenericMethodWithInterfaceConstraint<T>(T arg) where T : IDisposable
202+
{
203+
if (arg is null) throw new ArgumentNullException(nameof(arg));
204+
}
190205
}
191206
192207
class GenericType<T>
@@ -288,6 +303,21 @@ void GenericMethod<T>(T arg)
288303
{
289304
if (arg is null) throw new ArgumentNullException(nameof(arg));
290305
}
306+
307+
void GenericMethodWithClassConstraint<T>(T arg) where T : class
308+
{
309+
ArgumentNullException.ThrowIfNull(arg);
310+
}
311+
312+
void GenericMethodWithTypeConstraint<T>(T arg) where T : C
313+
{
314+
ArgumentNullException.ThrowIfNull(arg);
315+
}
316+
317+
void GenericMethodWithInterfaceConstraint<T>(T arg) where T : IDisposable
318+
{
319+
if (arg is null) throw new ArgumentNullException(nameof(arg));
320+
}
291321
}
292322
293323
class GenericType<T>

0 commit comments

Comments
 (0)