在 Fody/Mono.Cecil 中获取 CustomAttribute 的序列点
Get SequencePoint for CustomAttribute in Fody/Mono.Cecil
我正在编写一个 Fody 插件,我能够注入我的代码并向用户提供错误消息。我能够确定指令的序列点,但我找不到找到 CustomAttributes 序列点的方法。
我需要获取此信息,以便为调试器提供一个提示,提示在何处可以找到错误的位置,以防某个属性应用错误。
所以基本上我有这样的东西:
[MyAttribute]
public void Test()
{
}
现在想获取MyAttribute属性的SequencePoint
**编辑:** 当我投票(没有任何信息为什么)时,这里有一些额外的信息。我可以像这样访问指令的序列点:
public static SequencePoint GetSP(MethodDefinition method)
{
return method.Body.Instructions
.Where(instruction => instruction.SequencePoint != null)
.Select(instruction => instruction.SequencePoint)
.FirstOrDefault();
}
这对于指令来说工作得很好,但是当我访问一个属性时,我不确定如何获取序列点:
public static SequencePoint GetSP(MethodDefinition method)
{
var attribute = method.CustomAttributes.First();
// what to enter here to get SequencePoint of attribute?
}
这是不可能的。属性没有序列点。我建议您只使用方法的第一个序列点
我正在编写一个 Fody 插件,我能够注入我的代码并向用户提供错误消息。我能够确定指令的序列点,但我找不到找到 CustomAttributes 序列点的方法。
我需要获取此信息,以便为调试器提供一个提示,提示在何处可以找到错误的位置,以防某个属性应用错误。
所以基本上我有这样的东西:
[MyAttribute]
public void Test()
{
}
现在想获取MyAttribute属性的SequencePoint
**编辑:** 当我投票(没有任何信息为什么)时,这里有一些额外的信息。我可以像这样访问指令的序列点:
public static SequencePoint GetSP(MethodDefinition method)
{
return method.Body.Instructions
.Where(instruction => instruction.SequencePoint != null)
.Select(instruction => instruction.SequencePoint)
.FirstOrDefault();
}
这对于指令来说工作得很好,但是当我访问一个属性时,我不确定如何获取序列点:
public static SequencePoint GetSP(MethodDefinition method)
{
var attribute = method.CustomAttributes.First();
// what to enter here to get SequencePoint of attribute?
}
这是不可能的。属性没有序列点。我建议您只使用方法的第一个序列点