zoukankan      html  css  js  c++  java
  • C#判断是否运行在调试模式下

    很多情况下我们希望一些调试信息不输出,但又不至于用到trace和debug的一些功能,仅仅是包一下几句话,非调试状态就不运行,有这些用法
    using   System.Diagnostics; 
    
    class   XY 
    { 
          [Conditional( "DEBUG ")] 
          public   static   void   DebugLog(string   in_string) 
          { 
                Console.WriteLine(in_srting); 
          } 
    
          public   static   int   Main(string[]   in_args) 
          { 
                  DebugLog( "This   is   a   test "); 
                  return   5; 
            } 
    } 
     
    if   (System.Environment.StackTrace.ToLower().IndexOf( ":line ")> =0) 
      Console.WriteLine( "debug "); 
    else 
      Console.WriteLine( "release ");
    string   buildtype; 
    try 
    { 
    bool   found   =   Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute),   false).Length   >   0; 
    buildType   =   found   ?   "Debug "   :   "Release "; 
    } 
    catch 
    { 
    buildType   =   " <error> "; 
    }
    #If   DEBUG   Then 
    
              '调试状态下运行 
                    Else 
    
    #End   If
  • 相关阅读:
    内部类
    抽象类与接口
    多态
    继承
    封装
    创建对象的内存分析
    构造器
    面向对象 类与对象
    uniapp跳转
    uniapp-组件引用错误,仅支持 import 方式引入组件
  • 原文地址:https://www.cnblogs.com/walkerwang/p/2022435.html
Copyright © 2011-2022 走看看