|
|
|
|
|
|
Moke Blog
|
 |
|
|
|
|
|
Moke Blog
|
 |
|
|
|
|
|
|
VS2005 - Customizing Code Snippets
|
 |
|
Location: Blogs Moke Blog |
 |
| Posted by: Rick Mokros |
5/23/2007 1:48:00 PM |
In Visual Studio 2005 when you right-click on a method and select "Generate Method Stub" the following code is generated.
|
|
public bool IsDogLoose()
{
throw new Exception("The method or operation is not implemented.");
} |
Wouldn't the generated code look 'nicer" if it just threw a "NotImplemented" exception like this...
|
public bool IsDogLoose()
{
throw new NotImplementedException();
} |
Although this might seem petty, it is pretty cool to note that you can customize any of the standard code snippets by opening the appropriate code snippet in your favorite xml editor. You can find the code snippets here
c:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Refactoring\
The code snippet for GenerateMethodStub is called MethodStub.snippet and looks like this.
<?xml version="1.0" encoding="utf-8"?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>Method Stub - Body</Title> <Description>Snippet for generating method stub with a body</Description> <Author>Microsoft Corporation</Author> <SnippetTypes> <SnippetType>Refactoring</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal Editable="true"> <ID>signature</ID> <Default>signature</Default> </Literal> <Literal> <ID>Exception</ID> <Function>SimpleTypeName(global::System.Exception)</Function> </Literal> </Declarations> <Code Language="csharp"> <![CDATA[$signature$ { $end$throw new $Exception$("The method or operation is not implemented."); }]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> |
Ah, I think I can figure this out now. Change $Exception$ to $NotImplementedException$.
There you go... Customize the snippets to your liking... |
|
| Permalink |
Trackback |
|
|
|
|
|
|
|
|
|
|