zoukankan      html  css  js  c++  java
  • Effective C# 学习笔记(四)使用Conditional Attributes 替代 #if

    用法

    [Conditional("DEBUG"),

    Conditional("TRACE")]

    private void CheckState()

    {

    // Grab the name of the calling routine:

    string methodName =

    new StackTrace().GetFrame(1).GetMethod().Name;

    Trace.WriteLine("Entering CheckState for Person:");

    Trace.Write("\tcalled by ");

    Trace.WriteLine(methodName);

    Debug.Assert(lastName != null,

    methodName,

    "Last Name cannot be null");

    Debug.Assert(lastName.Length > 0,

    methodName,

    "Last Name cannot be blank");

    Debug.Assert(firstName != null,

    methodName,

    "First Name cannot be null");

    Debug.Assert(firstName.Length > 0,

    methodName,

    "First Name cannot be blank");

    Trace.WriteLine("Exiting CheckState for Person");

     

    }

    private void CheckStateBad()

    {

    // The Old way:

    #if BOTH

    Trace.WriteLine("Entering CheckState for Person");

    // Grab the name of the calling routine:

    string methodName =

    new StackTrace().GetFrame(1).GetMethod().Name;

    Debug.Assert(lastName != null,

    methodName,

    "Last Name cannot be null");

    Debug.Assert(lastName.Length > 0,

    methodName,

    "Last Name cannot be blank");

     

    Debug.Assert(firstName != null,

    methodName,

    "First Name cannot be null");

    Debug.Assert(firstName.Length > 0,

    methodName,

    "First Name cannot be blank");

    Trace.WriteLine("Exiting CheckState for Person");

    #endif

    }

     

    定义组合变量

    #if ( VAR1 && VAR2 )

    #define BOTH

    #endif

  • 相关阅读:
    bzoj 4008 亚瑟王 期望概率dp
    t[..., 1, tf.newaxis]
    Keras learning_phase()和learning_phase_scope()
    Keras Sequential模型和add()
    Keras克隆层
    Keras搭建一个Wide & Deep 神经网络
    1 链表的数据结构
    海康威视2017软件精英挑战赛初赛题目
    2016年倒计时两天
    可自定义片头的腾讯视频无广告可全屏调用代码
  • 原文地址:https://www.cnblogs.com/haokaibo/p/2096529.html
Copyright © 2011-2022 走看看