[英]How do I get a warning in Visual Studio when async methods don't end in 'Async'?
How can I get Visual Studio to give me a naming warning each time I create an asynchronous method that doesn't end in "Async"?每次创建不以“Async”结尾的异步方法时,如何让 Visual Studio 给我一个命名警告?
It's the recommended convention for asynchronous methods, but I often find myself forgetting to add that suffix and a warning would be useful.这是异步方法的推荐约定,但我经常发现自己忘记添加该后缀,警告会很有用。
From Options ,从选项,
In addition to Visual Studio Text Editor Settings, you can create portable, custom editor settings .editorconfig
file.除了 Visual Studio 文本编辑器设置之外,您还可以创建可移植的自定义编辑器设置
.editorconfig
文件。 Visual Studio 2017 natively supports .editorconfig
files. Visual Studio 2017 本身支持
.editorconfig
文件。
By creating the .editorconfig
file as part of the repository and pushing it to the repository, you can enforce consistent coding styles for everyone that works in that codebase, regardless of their Visual Studio Text Editor Settings.通过将
.editorconfig
文件创建为存储库的一部分并将其推送到存储库,您可以为在该代码库中工作的每个人强制执行一致的编码样式,而不管他们的 Visual Studio 文本编辑器设置如何。
The Coding conventions you use on your personal projects may differ from those used on your team's projects.
您在个人项目中使用的编码约定可能与您团队项目中使用的不同。 EditorConfig files resolve this problem by enabling you to have a configuration for each scenario.
EditorConfig 文件通过使您能够为每个场景进行配置来解决此问题。
EditorConfig settings take precedence over global Visual Studio text editor settings.
EditorConfig 设置优先于全局 Visual Studio 文本编辑器设置。
To do so:这样做:
In the Solution Explorer , select the Solution, Project or a folder in the project, depending on the scope which you want to apply the naming rule.在解决方案资源管理器中,根据要应用命名规则的范围选择解决方案、项目或项目中的文件夹。
Right click and select Add New Item or Press Ctrl + Shift + A右键单击并选择添加新项目或按Ctrl + Shift + A
.editorconfig
as file name..editorconfig
作为文件名。 Note: The file location can be even in parent folder of your solution.注意:文件位置甚至可以在解决方案的父文件夹中。 It's not necessary to have it in solution.
没有必要把它放在解决方案中。
Paste the following content in the file:将以下内容粘贴到文件中:
# Top-most EditorConfig file
root = true
[*.{cs,vb}]
# Async methods should have "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_rule.async_methods_end_in_async.severity = suggestion
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.word_separator =
More Information:更多信息:
The Microsoft.VisualStudio.Threading.Analyzers
analyzer offers this under the rule VSTHRD200 Microsoft.VisualStudio.Threading.Analyzers
分析器在规则 VSTHRD200 下提供此功能
More info here https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md更多信息在这里https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.