use*_*861 9 c# visual-studio visual-studio-2017
在Visual Studio 2017中,在" 快速操作和重构 "菜单中,当我单击" 实现接口 "时,我获得了使用C#的新功能的实现,如下所示:
public int ConnectionTimeout => throw new NotImplementedException();
Run Code Online (Sandbox Code Playgroud)
问题是我的公司正在使用C#5,所以我们不能使用这种新的语法.我知道Visual Studio的旧版本会生成此代码:
public int ConnectionTimeout { get { throw new NotImplementedException(); } }
Run Code Online (Sandbox Code Playgroud)
有没有办法让Visual Studio 2017执行此操作?我已经将我的项目设置为使用C#5进行编译.
编辑:我注意到代码生成器不一致.如果接口具有仅具有getter的bool成员,则它使用旧语法.否则它使用新语法.这让我觉得我运气不好.
private interface myint
{
bool bool1 { get; }
bool bool2 { get; set; }
bool bool3 { set; }
int int1 { get; }
int int2 { get; set; }
int int3 { set; }
string string1 { get; }
string string2 { get; set; }
string string3 { set; }
}
private class myclass : myint //I clicked "Implement Interface" on this
{
public bool bool1
{
get
{
throw new NotImplementedException();
}
}
public bool bool2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool bool3 { set => throw new NotImplementedException(); }
public int int1 => throw new NotImplementedException();
public int int2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int int3 { set => throw new NotImplementedException(); }
public string string1 => throw new NotImplementedException();
public string string2 { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string string3 { set => throw new NotImplementedException(); }
}
Run Code Online (Sandbox Code Playgroud)
转到工具 - >选项 - >文本编辑器 - >代码样式 - >常规,滚动到代码块首选项部分并更改首选项对于属性,对于索引器和对于访问者从"首选表达式块"(默认)更改为"首选块体" ".
| 归档时间: |
|
| 查看次数: |
2328 次 |
| 最近记录: |