[英]Get SequencePoint for CustomAttribute in Fody/Mono.Cecil
我正在編寫Fody Addin,可以注入代碼並向用戶提供錯誤消息。 我能夠確定指令的順序點,但是找不到找到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?
}
這是不可能的。 屬性沒有序列點。 我建議您只使用第一個序列點作為方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.