本文介绍了如何检测C#Windows窗体code为Visual Studio中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个变量或preprocessor不变,允许知道code为Visual Studio中的?

Is there a variable or a preprocessor constant that allows to know that the code is executed within the context of Visual Studio?

推荐答案

尝试Debugger.IsAttachedDesignMode财产或获得或组合,相应的

Try Debugger.IsAttached or DesignMode property or get ProcessName or a combination, as appropriate

Debugger.IsAttached // or
LicenseUsageMode.Designtime // or
System.Diagnostics.Process.GetCurrentProcess().ProcessName

下面是一个<一个href=\"http://voidnish.word$p$pss.com/2009/06/21/checking-for-design-mode/\">sample

public static class DesignTimeHelper {
    public static bool IsInDesignMode {
        get {
            bool isInDesignMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime || Debugger.IsAttached == true;

            if (!isInDesignMode) {
                using (var process = Process.GetCurrentProcess()) {
                    return process.ProcessName.ToLowerInvariant().Contains("devenv");
                }
            }

            return isInDesignMode;
        }
    }
}

这篇关于如何检测C#Windows窗体code为Visual Studio中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:06