用的是 Visual Studio 2017 ,请问在定义私有成员变量时,如何让 VS 的 suggested name 前面加上下划线?
在解决方案的根目录下添加 .editorconfig 文件并在其中添加下面的内容:
root = true [*.cs] dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal dotnet_naming_style.camel_case_underscore_style.required_prefix = _ dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
重启VS后搞定
参考自:
mark一下,顺便还是那句话,这是洁癖~~~
直接在 VS 中的设置方法:在 Tools -> Options -> Text Editor -> C# -> Code Style -> Naming 中点击 "Manage naming styles" ,添加一条标题为 "Begin with " 的 style ,在 Required Prefix 中填上 _
,然后添加一条规则:Specification 为 "Private or Internal Field" ,Required Style 为 "Begin with ",Severity 为 "Suggestior"
这是洁癖,需要治,看到构造函数中
public xxx(UploadOptions options)
{
this.options=options;
}
就觉得不爽,好的办法是强迫自己多看那些写法风骚,命名诡异的项目,恶心着恶心着就好了。
https://msdn.microsoft.com/en-us/library/ee372314.aspx