Skip to content

Commit 06bef88

Browse files
committed
fix: improve null safety in DependencyAnalyzer for SourceAssembly retrieval
1 parent a99e315 commit 06bef88

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

CodeLineCounter/Services/DependencyAnalyzer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ public static void AnalyzeFile(string filePath, string sourceCode)
118118
{
119119
SourceClass = GetSimpleTypeName(classDeclaration),
120120
SourceNamespace = classDeclaration.Ancestors().OfType<NamespaceDeclarationSyntax>().FirstOrDefault()?.Name.ToString() ?? "",
121-
SourceAssembly = classDeclaration.SyntaxTree.GetRoot().DescendantNodes().OfType<CompilationUnitSyntax>().FirstOrDefault()?.Usings.FirstOrDefault()?.Name.ToString() ?? "",
121+
SourceAssembly = classDeclaration.SyntaxTree.GetRoot()
122+
.DescendantNodes()
123+
.OfType<CompilationUnitSyntax>()
124+
.FirstOrDefault()?
125+
.Usings.FirstOrDefault()?
126+
.Name?.ToString() ?? "",
122127
TargetClass = dependency.Split('.')[(dependency.Split('.').Length - 1)],
123128
TargetNamespace = dependency.Contains(".") ? dependency.Substring(0, dependency.LastIndexOf('.')) : "",
124129
TargetAssembly = dependency.Contains(".") ? dependency.Substring(0, dependency.LastIndexOf('.')) : "",

0 commit comments

Comments
 (0)