Wednesday, January 6, 2010

Not implemented? Implemented.

I use the System.NotImplementedException a lot, whenever I create a new method I have it throwing this until I have let tests drive actual functionality of the method. There is a slight danger in this though (although better than the alternative) in that I might forget to implement a function and this exception creeps into production.

The other day I modified the snippet I use so that it outputs pre processor directives, so that the compiler will refuse to compile the code if I forget to implement such a method.

#if DEBUG
            throw new NotImplementedException();
#else
#error "Must be implemented to compile in configurations where the DEBUG constant is not defined."
#endif