Resharper custom patterns change method name

别说谁变了你拦得住时间么 提交于 2019-11-29 00:29:35

问题


I want to change method signature from

public static async Task Load()

to

public static async Task LoadAsync()

How to define a custom patterns in ReSharper?


回答1:


If I understood you correctly, you want to define a custom pattern to change async Task Method() signature to async Task MethodAsync(). If so, this is possible by using Custom Patterns!

For this, go to ReSharper's Options, then Code Inspection → Custom Patterns:

  • Click Add Pattern

  • In the new dialog, make sure Replace is selected

  • Type the Search and Replace pattern exactly as they appear in the image below. Depending on your ReSharper versions, the placeholder parameters should appear automatically. If not, press the Add Placeholder button.

  • Double click the method placehoder, and add the following RegEx: \b\w+(?<!Async)\b - this tells only to match method names NOT ending in Async already.

  • In the Pattern Severity combobox select Show as Hint or Show as Suggestion, depending on your preference.

  • Click Add, then Save (or Save To → Team Shared, to have this pattern stored in the team-shared settings, available to all your teammates).

ReSharper will now flag all public async Task methods that are not already end with Async:

And you can now press Alt-Enter to quick-fix it!



来源:https://stackoverflow.com/questions/22502175/resharper-custom-patterns-change-method-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!