Changing the default method stub generated by Visual Studio 2005's Generate Method Stub refactoring to use NotImplementedException
Posted: (EET/GMT+2)
You might have noticed while writing your C# code in Visual Studio 2005 that whenever you write a name of a method that doesn't yet exist in your class, Visual Studio suggest to generate a method stub for your when you press Shift+Alt+F10,M while your cursor (caret) is on the name of the (yet) non-existing method.

Now, the default-generated method uses the basic System.Exception class to throw an exception with the message "The method or operation is not implemented." because you haven't in fact yet written any code to the method's body. However, the .NET Base Class Library also contains a specific exception type for this purpose, named the System.NotImplementedException. This brings into mind an idea: would it be possible to change the default method stub generated by Visual Studio? Luckily, the answer is yes.
About a year ago, Microsoft's Anson Horton (the Program Manager for the Visual C# IDE) blogged about this, and showed how to edit the "MethodStubBody.snippet" file under the default directory "C:\Program Files\Microsoft Visual Studio 2005\VC#\Snippets\1033\Refactoring" so that the generated code will throw a NotImplementedException instead of a regular Exception.
Having made the change myself, I quickly noticed that it would be great if the error message itself would display the name of the method in question, because the default error message shown is simply "The method or operation is not implemented." even with NotImplementedException, and thus requires you to check the call stack (or use the debugger) to see which method was not implemented. However, if you tweak the MethodStubBody.snippet file just a little bit more, you can easily get this feature done. By using the special "$signature$" macro (for a lack of a better word), you can insert the name of the method to the error message. So in the end, I ended up editing the MethodStubBody.snippet file like Anson Horton described, but also by changing the actual code to:
<Code Language="csharp">
<![CDATA[$signature$
{
$end$throw new $Exception$("The method or operation " +
"is not implemented: $signature$");
}]]>
</Code>
This change has proved to be just perfect for my needs. Try it and see what you think. Oh by the way, this suggestion has already been made to the Visual Studio Connect site with the ID 92654.