Best Way to Avoid Errors due to Settings/Configuration BEFORE Runtime
A common problem is that programs may compile ok, but external (user/environment) settings may cause applications to crash during runtime.
Aside from perfo开发者_开发技巧rming checks all over the code, (alas actually performed during Runtime), I would like to have rule sets to assert during build that, at least default values settings, are coherent.
The simplest case may be, if default settings are hardcoded :
Directory defaultDir = new Directory("D:\\Data");
UserLogin usr1 = "Jesse";
UserLogin usr2 = "James";
(yeah, "Booh"; this is an example, please DO NOT comment/answer on that unsignificant detail... I know it's hard for some of you, but please REFRAIN ! :-) )
So, is there a SIMPLE way to check DURING Build, that "D:\Data" exists, and that usr1 and usr2 do have different login strings etc...
I am sure there are assertion mechanisms in .Net, and maybe Unit Testing (I'd rather avoid the latter cause it may be oversized for the very light usage/need in this particular case. But I guess that's what Unit Tests are designed for too...)
In your project properties, you can set a command to run before the build, so you can create an exe that checks your settings, and run it in the "pre build event command line"
精彩评论