File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Core/Microsoft.NetCore.Analyzers/Runtime
UnitTests/Microsoft.NetCore.Analyzers/Runtime Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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
192207class 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
293323class GenericType<T>
You can’t perform that action at this time.
0 commit comments