考虑下面的守则:
#if DEBUG
if (Systems.Contains(system))
throw new InvalidOperationException("System already registered");
#endif
Debug.Assert(!Systems.Contains(system), "System already registered");以前,我曾经做过前者,后来我发现了Debug.Assert。
为什么我不应该总是喜欢Debug.Assert?
它只存在于调试代码中(在我看来,[Conditional("DEBUG")]).
发布于 2011-11-23 12:29:40
您可以始终使用Debug.Assert(),因为该类也符合调试条件:
[Conditional("Debug")]向编译器指示,除非定义了指定的条件编译符号,否则应忽略方法调用或属性。
ConditionalAttribute应用于调试和跟踪类中定义的方法。
http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx
https://stackoverflow.com/questions/8242172
复制相似问题