Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

How to change the generated method stub code for C#

Before you apply this tip...

  • I strongly recommend that you backup any snippets installed by VS that you may want to modify.  Take it from a former code Snippet QA that you will want to do this.
  • This tip requires having access to your Program Files directory, so use appropriate caution
  • Do not change the title for any of the VS installed snippets

Create a function that hasn't been defined yet and use the smart tag to generate a method stub.

Function not defined yet

You'll get a method stub defined for bar() that throws a new Exception class.

Default Generated Method Stub

But let's say instead of throwing an Exception class, you wanted it to throw NotImplementedException.

Open up
\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Refactoring\MethodStub.snippet

And change
<Function>SimpleTypeName(global::System.Exception)</Function>
to
<Function>SimpleTypeName(global::System.NotImplementedException)</Function>

You could use this approach to define your custom method stubs as you see fit.

Tags:
Suggest a Tip!

Posted: Wednesday, May 24, 2006 5:03 PM by saraford

Comments

Jason Haley said:

# May 25, 2006 10:19 AM

Sara Ford's WebLog said:

A previous tip of the week mentioned how to use the SimpleTypeName() snippet function.&amp;nbsp; Here’s how...
# June 5, 2006 12:56 PM

BooGhost said:

Hi Sara, On this same-ish topic.. How would one go about changing the VS-generated code-completion items? Like.. I work primarily in VB.. so when I type.. Public Property Foo As String , VS generates the rest of the property. I'd like to change what is generated. Thanks, -Boo
# September 27, 2006 1:40 PM

卜海清 said:

今天看到这个挺COOL的功能,以前一直没有注意到!!挺实用的一个小功能!!具体请参看SaraFord的博客http://blogs.msdn.com/saraford/archive/20...

# January 8, 2009 4:06 AM
New Comments to this post are disabled
Page view tracker