问题
Is it possible to change the stub used to implement interfaces in Visual Studio 2008?
For instance, when I choose eitherImplement interface 'IMyInterface'
orExplicitly implement interface 'IMyInterface'
Instead of a number of properties that look like this:
public string Comment
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
I'd like my properties to use the C# 3.0 auto-implemented properties and look like this:
public string Comment {get;set;}
I want to do this to avoid forcing this interface to be an abstract class.
I've looked through the snippets in the Visual Studio folder, but I didn't see any that would be appropriate. I've also googled and searched SO, and found nothing.
If this isn't possible, does anyone have a macro I can steal?
Thanks.
edit: I have tried editing the snippets located in C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Refactoring but these changes don't change the implementation. I've tried making the changes, then reopening Visual Studio, which doesn't work. Am I doing something wrong here?
回答1:
It looks like ReSharper may be the only way for me to go about this.
I just revisited this issue and found that you can change the snippet used by Visual Studio:
You can modify the stub Visual Studio uses to implement interfaces (both implicit and explicit) by editing the file:Microsoft Visual Studio 10.0\VC#\Snippets\1033\Refactoring\PropertyStub.snippet
I’ve changed the code segment in my file to:
<Code Language="csharp">
<![CDATA[ $signature$ { $GetterAccessibility$ get; $SetterAccessibility$ set;} $end$]]>
</Code>
来源:https://stackoverflow.com/questions/2608966/changing-property-stubs-for-interface-refactoring