如何使用 Mono.Cecil 0.10.2 获取指令行号?

How to get line number of Instruction using Mono.Cecil 0.10.2?

我有一个 Mono.Cecil.Cil.Instruction 对象代表代码中的方法调用。我想获取源文件中方法调用的行号。

这篇旧帖子提到使用指令对象的 SequencePoint 属性:How to get source/line number for IL instruction using Mono.Cecil。但是,我在 Mono.Cecil.

的 0.10.2 版本中看不到这个 属性

在此处找到解决方案:http://cecil.pe/post/149243207656/mono-cecil-010-beta-1

Instruction.SequencePoint 已删除。您现在必须使用:

MethodDefinition method = ...;
Instruction instr = ...;
SequencePoint seqPoint = method.DebugInformation.GetSequencePoint(instr);