惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - nestea

Method 'Post' of object 'IOWSPostData' failed(方法'POST'作用于对象'IOWSPostData'时失败) 用Win XP安装盘修复系统文件 手机呼叫流程 XML配置字符串中特殊字符的处理 - nestea - 博客园 关于BackgroundWorker的使用 分布式缓存系统Memcached简介与实践[转] web应用程序中使用MemcachedClient (转载) 一些很酷的.Net技巧(转载) sql server中的decimal或者numeric的精度问题 (转载) 使用BackgroundWorker组件进行异步操作编程(转载) 操作DataTable中动态的行,一点收集整理资料。 xml转换成DataTable - nestea - 博客园 数字的进制(2进制,8进制,16进制) C#中父窗口和子窗口之间实现控件互操作 (转载) 开放式并发冲突检测的四种方法 MDX 中的重要概念 (MDX) 实用工具-文件夹实时同步工具 (群集服务器拷贝) 用windows 2003建立VPN 连接(转载) - nestea Windows 2003下VPN服务器架设攻略 (转载) - nestea
预处理命令之条件编译(转)
nestea · 2009-05-07 · via 博客园 - nestea

我初学.NET 时通常会这样写条件编译:

        /// <summary>
       
/// 不推荐的条件编译方法
       
/// </summary>
        public void CheckData(object o)
        {
             #
if DEBUG
                  //Do Some
             #endif
        }

其实.net 框架提供了条件编译的良好方法,推荐写法:

         /// <summary>
       
/// 定义一个方法的条件编译,推荐方式
       
/// </summary>
        [Conditional("Debug")]
       
public void CheckData()
        {
           
//Todo check
        }

如果是不是方法级别的条件编译,我们的写法又回归了:

 public void CheckData<T>(List<T> list)
        {
           
try
            {
               
//Do something
            }
           
catch (Exception ex)
            {
                logger.InfoFormat(ex.Message);
#
if DEBUG
               
throw new AbnormalDataException(String.Format("新增记录异常{0}", ex.Message), ex);
#else
                
throw new AbnormalDataException("新增记录异常",ex);
#endif
            }
        }

备注:

1.标识符 Debug #DEBUG 区分大小写

2.善用Conditional ,拆分Simple Method

 **********************************************

还有这样的文章:

http://www.cnblogs.com/iimax/archive/2009/03/16/1413257.html

http://www.cnblogs.com/kane_zzt/archive/2008/12/03/1346556.html

http://www.cnblogs.com/thinhunan/archive/2005/04/18/139518.html

http://www.cnblogs.com/piccolo/articles/250707.html

http://www.cnblogs.com/blognetspace/archive/2009/02/12/1388943.html

http://www.cnblogs.com/muddle/archive/2004/04/07/5402.html

http://www.cnblogs.com/zhangaz1/articles/1175800.html