[英]Refactoring “Implement Interface” using auto properties VS2015
I am trying to get Visual Studio 2015 (14.0) to use auto properties when implementing an interface using refactoring for C#. 我试图让Visual Studio 2015(14.0)在使用C#重构实现接口时使用自动属性。
Ie I want this; 就是我想要这个;
public object SomeProperty { get; set; }
as opposed to this; 与此相反;
public object SomeProperty
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
I have accomplished this in past versions of Visual Studio by editing the code snippet file (instructions here ) but I cannot get this to work using Visual Studio 2015. 我已经在Visual Studio的过去版本中通过编辑代码片段文件( 此处的说明)完成了此操作,但我无法使用Visual Studio 2015来实现此功能。
You can solve by editing the PropertyStub.snippet
您可以通过编辑
PropertyStub.snippet
来解决
Just go to C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC#\\Snippets\\1033\\Refactoring
open PropertyStub.snippet
and edit: 只需转到
C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC#\\Snippets\\1033\\Refactoring
打开PropertyStub.snippet
并编辑:
$GetterAccessibility$ get
{
$end$throw new $Exception$();
}
$SetterAccessibility$ set
{
throw new $Exception$();
}
to 至
$GetterAccessibility$ get;
$SetterAccessibility$ set;
Ok, so I stumbled upon the answer during my testing of VS2019 Preview (16.0). 好的,所以我在测试VS2019 Preview(16.0)时偶然发现了答案。
In the main menu bar Tools --> Options --> Text Editor --> C# --> Advanced
look for the option Implement Interface or Abstract Class
under When generating properties
choose prefer auto properties
. 在主菜单栏中的
Tools --> Options --> Text Editor --> C# --> Advanced
查找选项Implement Interface or Abstract Class
在When generating properties
选择prefer auto properties
。
This results in the same outcome that snippets used to take care of pre VS2015. 这导致与用于处理VS2015之前的片段相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.