Changing property stubs for Interface refactoring

拥有回忆 提交于 2019-12-11 06:50:01

问题


Is it possible to change the stub used to implement interfaces in Visual Studio 2008?

For instance, when I choose either
Implement interface 'IMyInterface'
or
Explicitly 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!