需要帮助从堆栈跟踪字节偏移量中查找源代码行

时间:2012-05-11 07:25:17

标签: .net windows-phone-7

任何人都可以告诉我如何在wp7中使用字节偏移(来自堆栈跟踪)找到源代码行吗?

1 个答案:

答案 0 :(得分:0)

这是我用过的东西,但它不是特定于手机的胜利 - 但它可能会对你有所帮助:

private static string lineAndMethod() {
    int stack_frame_depth = 5;
    StackFrame sf = new StackFrame(stack_frame_depth, true);
    while (sf.GetFileName() == null && stack_frame_depth > 0)
    sf = new StackFrame(--stack_frame_depth, true);
    if (sf.GetFileName() == null) // Failed.
        return "";
    MethodBase mb_caller = sf.GetMethod();
    retrun string.Format("{0}, {1}: {2}]",
                         Path.GetFileName(sf.GetFileName()),
                         mb_caller.Name, sf.GetFileLineNumber());
}
相关问题