更改接口重构的属性存根 [英] Changing property stubs for Interface refactoring
问题描述
是否可以更改用于在Visual Studio 2008中实现接口的存根?
例如,当我选择
实现界面'IMyInterface'
或
明确实现接口'IMyInterface'
而不是数字看起来像这样的属性:
public string Comment
{
get
{
抛出新的NotImplementedException();
}
设置
{
抛出新的NotImplementedException();
}
}
我希望我的属性能够使用C#3.0自动实现的属性,如下所示:
public string Comment {get; set;}
我想这样做是为了避免强迫这个接口成为一个抽象类。
<我查看了Visual Studio文件夹中的片段,但我没有看到任何合适的片段。我也用Google搜索并搜索了SO,但一无所获。
如果这不可能,有没有人有一个我可以偷的宏?
谢谢。
编辑:我已尝试修改 C中的代码段:\Program Files \ Microsoft Visual Studio 9.0 \ VC#\Snippets\1033 \Refactoring
但这些更改不会更改实现。我已经尝试进行更改,然后重新打开Visual Studio,这不起作用。我在这里做错了吗?
看起来ReSharper可能是我解决这个问题的唯一方法。
我刚刚重新访问此问题,发现您可以更改Visual Studio使用的代码段:
您可以修改存根Visual Studio用于通过编辑文件来实现接口(隐式和显式):
Microsoft Visual Studio 10.0 \ VC#\ Snippets \ 1033 \ Refactoring \ PropertyStub.snippet
我已将文件中的代码段更改为:
< Code Language =csharp>
<![CDATA [$ signature $ {$ GetterAccessibility $ get; $ SetterAccessibility $ set;} $ end $]]>
< /代码>
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?
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>
这篇关于更改接口重构的属性存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!