Skip to content

Commit

Permalink
Merge pull request #163 from lucaslorentz/fix-nullreference-exception
Browse files Browse the repository at this point in the history
Fix null reference exceptions in ResolveOriginalMethod
  • Loading branch information
lucaslorentz authored Apr 4, 2023
2 parents c4f476c + 64be0ef commit 4d1ebaf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/MiniCover.Core/Extensions/MethodDefinitionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ public static bool IsExcludedFromCodeCoverage(this MethodDefinition methodDefini

public static MethodDefinition ResolveOriginalMethod(this MethodDefinition methodDefinition)
{
var originalMethodName = ExtractOriginalMethodName(methodDefinition.Name)
?? ExtractOriginalMethodName(methodDefinition.DeclaringType.Name);
var originalMethodName = ExtractOriginalMethodName(methodDefinition.Name);

if (originalMethodName == null && methodDefinition.DeclaringType != null)
originalMethodName = ExtractOriginalMethodName(methodDefinition.DeclaringType.Name);

if (!string.IsNullOrEmpty(originalMethodName)
&& methodDefinition.DeclaringType.IsCompilerGenerated())
&& methodDefinition.DeclaringType != null
&& methodDefinition.DeclaringType.IsCompilerGenerated()
&& methodDefinition.DeclaringType.DeclaringType != null)
{
var originalMethod = methodDefinition.DeclaringType.DeclaringType.Methods
.FirstOrDefault(m => m.Name == originalMethodName);
Expand Down

0 comments on commit 4d1ebaf

Please sign in to comment.