Reputation: 4970
Is it possible to make Resharper's tool "Cleanup code" (in Visual Studio) to change all var
to explicit types?
Example: I'd like this:
var person = new Person();
to be changed to this:
Person person = new Person();
Edit after suggested solutions:
Maybe I'm doing something wrong, but it doesn't work for me:
Upvotes: 8
Views: 3801
Reputation: 8763
NOTE: you can also stop resharper from defaulting to var when doing "introduce variable".
These settings are under Code Editing --> C# --> Code Style
Upvotes: 2
Reputation: 195
You can set this up in the (Resharper) options under Code Cleanup. Just create a new profile/modify an existing one and then navigate to C#->Use 'var' in declaration. Set the "Replace direction" to "Can (change) 'var' to type usage" and "Local variable declaration style" to "Always use explicit type"
Upvotes: 9
Reputation: 75598
Yes. In the "Code cleanup" tool, under "Use 'var' in declaration" set the "Replace direction" to "Can 'var' to type usage".
Upvotes: 2