C# Fody/Mono.Cecil:在调试器中隐藏行

C# Fody/Mono.Cecil:在调试器中隐藏行,c#,.net,pdb,mono.cecil,fody,C#,.net,Pdb,Mono.cecil,Fody,我正在开发一个fody addin(使用mono.cecil),并在方法的开头插入一些代码。我希望调试器跳过注入的代码 我在这里找到了一些信息: 所以我尝试将注入指令的序列点更新为行号0xfeefee 我使用以下代码执行此操作: public static void Inject(MethodDefinition method, List<Instruction> instructions) { var methodInstructions = met

我正在开发一个fody addin(使用mono.cecil),并在方法的开头插入一些代码。我希望调试器跳过注入的代码

我在这里找到了一些信息:

所以我尝试将注入指令的序列点更新为行号0xfeefee

我使用以下代码执行此操作:

    public static void Inject(MethodDefinition method, List<Instruction> instructions)
    {
        var methodInstructions = method.Body.Instructions;

        int index = 0;
        var sequencePoint = method.Body.Instructions
            .Where(instruction => instruction.SequencePoint != null)
            .Select(instruction => instruction.SequencePoint)
            .FirstOrDefault();

        if (method.HasBody && sequencePoint != null && sequencePoint.Document != null)
        {
            var instruction = instructions[0];
            instruction.SequencePoint = new SequencePoint(sequencePoint.Document);
            instruction.SequencePoint.StartLine = 0xfeefee;
            instruction.SequencePoint.EndLine = 0xfeefee;
        }

        foreach (var instruction in instructions)
        {
            methodInstructions.Insert(index++, instruction);
        }

        method.Body.OptimizeMacros();
    }
publicstaticvoidinject(方法定义方法,列表说明)
{
var methodInstructions=method.Body.Instructions;
int指数=0;
var sequencePoint=方法.Body.Instructions
.Where(指令=>instruction.SequencePoint!=null)
.Select(指令=>instruction.SequencePoint)
.FirstOrDefault();
if(method.HasBody&&sequencePoint!=null&&sequencePoint.Document!=null)
{
var指令=指令[0];
instruction.SequencePoint=新SequencePoint(SequencePoint.Document);
instruction.SequencePoint.StartLine=0xfeefee;
instruction.SequencePoint.EndLine=0xfeefee;
}
foreach(指令中的var指令)
{
方法说明。插入(索引++,说明);
}
方法.Body.OptimizeMacros();
}
这应该与NullGuard.Fody项目使用的代码基本相同,但不起作用。当我试图调试到注入代码的方法中时,仍然从VisualStudio获得一个源代码不可用的信息


是否需要执行其他操作,以便更新pdb文件?

尝试从查询中删除
Where
,以选择第一个序列点

如果方法的第一条指令具有序列点,则只需添加隐藏序列点