Apply a context action to an entire file
Is there any way to make Resharper apply a context action at every applicable site in a file?
In particular, in order to comply with coding standards, I 开发者_如何学JAVAwish to apply 'Specify type explicitly' to every 'var' declaration across a number of files.
In general, you can't apply a context action in multiple code positions. However, in the case of specifying type explicitly, you can use Code Cleanup to batch-apply this.
- Choose "ReSharper > Tools > Clean up code"
- Click "Edit Profiles"
- Click "Add" to create a new cleanup profile and specify a name for it (say, "goodbye var").
- In the list of profile settings, clear all check boxes to prevent unwanted code style changes.
- Under C# > Use 'var' in declaration, select "Do not change" for "Replace direction", and "Always use explicit type" in the other two drop-downs.
- Click "OK".
- Choose "ReSharper > Tools > Clean up code" once more, choose the "goodbye var" profile, and click "Run".
Note that you can invoke code cleanup in different scopes: step 7 above implies that you're calling it in the scope of the currently opened file. However, you can choose a wider scope (folder, project, solution) in the Solution Explorer and invoke Code Cleanup from there.
精彩评论