Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
695eec9
commit 1fabfa2
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Fody; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
using VerifyXunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public class CecilExtensionsTests : | ||
VerifyBase | ||
{ | ||
[Fact] | ||
public void GetSequencePointWithNoSymbols() | ||
{ | ||
var sequencePoint = ReadSequencePoint(false); | ||
Assert.Null(sequencePoint); | ||
} | ||
|
||
[Fact] | ||
public void GetSequencePointWithSymbols() | ||
{ | ||
var sequencePoint = ReadSequencePoint(true); | ||
Assert.NotNull(sequencePoint); | ||
} | ||
|
||
static SequencePoint? ReadSequencePoint(bool readSymbols) | ||
{ | ||
var assemblyPath = Path.Combine(Environment.CurrentDirectory, "DummyAssembly.dll"); | ||
var parameters = new ReaderParameters | ||
{ | ||
ReadSymbols = readSymbols | ||
}; | ||
var module = ModuleDefinition.ReadModule(assemblyPath, parameters); | ||
|
||
return module.GetType("DummyAssembly.Class1").Methods | ||
.Single(x => x.Name == "Method") | ||
.GetSequencePoint(); | ||
} | ||
|
||
public CecilExtensionsTests(ITestOutputHelper output) : | ||
base(output) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Linq; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Fody | ||
{ | ||
public static class CecilExtensions | ||
{ | ||
public static SequencePoint? GetSequencePoint(this MethodDefinition method) | ||
{ | ||
Guard.AgainstNull(nameof(method), method); | ||
return method.Body.Instructions | ||
.Select(instruction => method.DebugInformation.GetSequencePoint(instruction)) | ||
.FirstOrDefault(sequencePoint => sequencePoint != null); | ||
} | ||
} | ||
} |