16

In Visual Studio 2010, is it possible to change the default template used when implementing an interface?

I would like to change the implementation of properties from

public int MyProperty
{
    get
    {
        throw new NotImplementedException();
    }
    set
    {
        throw new NotImplementedException();
    }
}

to

public int MyProperty { get; set; }

Edit

so i tried to Edit PropertyStub.snippet but to no avail, it didn't change anything...

I found this question Changing property stubs for interface refactoring which says that ReSharper is the only way.

Anyone able to make this work, with example, cause the change i made did not seem to have any effects

2
  • Have a look at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring\PropertyStub.snippet (in the Code Snippets Manager: Refactoring\Property Stub for language Visual C#). If this is the one used by Visual Studio, I wonder if there's a way to modify it on a per-user basis rather than directly. Commented Sep 22, 2010 at 20:37
  • Kzu has the answer: blogs.clariusconsulting.net/kzu/… Commented Oct 27, 2011 at 8:47

1 Answer 1

15

Yes, it is possible to change this template. The C# IDE uses templates for the majority of it's code generation and the IDE. You can update these templates to control the code generation process. They are located in the following directory

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring

Note: The " (X86)" portion will be absent on 32 bit machines.

For this particular situation you want to change the PropertyStub.snippet file.

Sign up to request clarification or add additional context in comments.

6 Comments

Well I Tried but it didn't work... any requirement for this to work?
@moi_meme, did you restart VS?
Yes I did, many times... I tried just adding a contant and nothing changed... do yoou have a working example?
@LuisPalacios it does not work in 2015 -- See connect.microsoft.com/VisualStudio/feedback/details/1857694/… for more info.
@scaryman -- Of course not. Why would it? Why keep a useful feature when you can get rid of it for no good reason?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.