FatAlbert
FatAlbert

Reputation: 4970

Can Resharper change var to explicit types?

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:

image showing how the suggested solution doesn't work

Upvotes: 8

Views: 3801

Answers (3)

Derek
Derek

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

enter image description here

Upvotes: 2

Axel Wilczek
Axel Wilczek

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

Sjoerd
Sjoerd

Reputation: 75598

Yes. In the "Code cleanup" tool, under "Use 'var' in declaration" set the "Replace direction" to "Can 'var' to type usage".

Creating Custom Profiles

Upvotes: 2

Related Questions