Skip to content

Commit 60c43ae

Browse files
committed
Add extra checks for non-null method and ReducedFrom
Rather than assuming it won't be null.
1 parent 58406ea commit 60c43ae

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/DependencyInjection/AddServicesAnalyzer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static bool IsDDICode(SyntaxNode node, SemanticModel semantic)
6262
.Where(x => !IsDDICode(x.Invocation, semantic) && x.Symbol != null)
6363
.Select(x => new { x.Invocation, Method = (IMethodSymbol)x.Symbol! });
6464

65-
bool IsServiceCollectionExtension(IMethodSymbol method) => method.IsExtensionMethod &&
65+
bool IsServiceCollectionExtension(IMethodSymbol method) => method != null &&
66+
method.IsExtensionMethod &&
6667
method.ReducedFrom != null &&
6768
method.ReducedFrom.Parameters.Length > 0 &&
6869
method.ReducedFrom.Parameters[0].Type.Equals(servicesCollection, SymbolEqualityComparer.Default);
@@ -80,6 +81,7 @@ bool IsServiceCollectionExtension(IMethodSymbol method) => method.IsExtensionMet
8081
if (!usesAddServices &&
8182
invocations.Where(x =>
8283
IsServiceCollectionExtension(x.Method) &&
84+
x.Method.ReducedFrom != null &&
8385
x.Method.ReducedFrom!.GetAttributes().Any(attr => attr.AttributeClass?.Name == "DDIAddServicesAttribute"))
8486
.Any())
8587
{

0 commit comments

Comments
 (0)