I have a very well thought out object oriented structure to a large project that I am working on. However, in areas of my code I would like to toggle debug sections on and off through a set of variables located in one easy to access area. My question is whether this is a good practice or i开发者_JAVA百科f I should implement an even more convoluted passing scheme to pass debug parameters.
You should probably take a good look at the System.Diagnostics.Debug class and how it is implemented using the Conditonal attribute.
Build something like that. Ease of use is nothing against the complexity of being certain you turned it all off.
And of course C# doesn't have glbal variables anyway.
You should use the debug class that has numerous methods to handle debugging, which are removed when built in release mode. Also conditional methods would probably help you as well.
精彩评论