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

Community
  • 1
  • 1
moi_meme
  • 9,180
  • 4
  • 44
  • 63
  • 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. – dtb Sep 22 '10 at 20:37
  • Kzu has the answer: http://blogs.clariusconsulting.net/kzu/how-to-replace-default-interface-property-implementation-expansion-with-automatic-properties/ – Mark Seemann Oct 27 '11 at 08:47

1 Answers1

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.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454