debughelper.cs

来自「破解的飞信源代码」· CS 代码 · 共 41 行

CS
41
字号
namespace Imps.Utils
{
    using System;
    using System.Diagnostics;
    using System.Text;

    public static class DebugHelper
    {
        public static void BuildCallStackString(StringBuilder sb, int skipFrames)
        {
            StackTrace trace = new StackTrace(skipFrames + 1, true);
            for (int i = 0; i < trace.FrameCount; i++)
            {
                StackFrame frame = trace.GetFrame(i);
                if (i != 0)
                {
                    sb.Append("  ");
                }
                sb.Append(frame.GetMethod());
                string fileName = frame.GetFileName();
                if (!string.IsNullOrEmpty(fileName))
                {
                    sb.Append("; ");
                    sb.Append(fileName);
                    sb.Append(": ");
                    sb.Append(frame.GetFileLineNumber());
                }
                sb.AppendLine();
            }
        }

        public static string GetCallStackString(int skipFrames)
        {
            StringBuilder sb = new StringBuilder();
            BuildCallStackString(sb, skipFrames + 1);
            return sb.ToString();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?