c# 运行时判断是否为DEBUG模式

public static bool RunningModeIsDebug
        {
            get
            {

                var assebly = Assembly.GetEntryAssembly();
                if (assebly == null)
                {
                    assebly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
                }

                var debugableAttribute = assebly.GetCustomAttribute<DebuggableAttribute>();
                var isdebug = debugableAttribute.DebuggingFlags.HasFlag(DebuggableAttribute.DebuggingModes.EnableEditAndContinue);

                return isdebug;
            }
        }

参考

posted @ 2022-04-13 09:36  Hey,Coder!  阅读(949)  评论(0)    收藏  举报