Adding "Convert to ..." and "ToString" as a fix for valuetype mismatches

Would it be possible to add Convert.ToXXX() calls and .ToString() method
invokations for certain valuetype/string mismatches? I end up doing a
lot of these by hand for things like DataRow operations. It would nice
if Resharper could offer a more functional conversion from string to
Int32 and vice versa, as an example.

int myValue = 3;
string s = myValue;
^-- should suggest "Convert.ToString() and myValue.ToString()"

string s = "3";
int myValue = s;
^-- should suggest "Convert.ToInt32()"

Other fixes might include "Enum.Parse" calls:

string s = "MyEnum";
MyEnum xx = s;
^-- should suggest Enum.Parse()

Most conversions have a "well-known" framework method to convert them.
It would be nice if Resharper exposed these.

Thanks!
Matt.

1 comment
Comment actions Permalink

I added requests

http://www.intellij.net/tracker/resharper/viewSCR?publicId=5628

and

http://www.intellij.net/tracker/resharper/viewSCR?publicId=5629

As for converting from string to Enum using Enum.Parse(), I'm not sure if
it's used often enough and worth a quickfix.

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Would it be possible to add Convert.ToXXX() calls and .ToString()
method invokations for certain valuetype/string mismatches? I end up
doing a lot of these by hand for things like DataRow operations. It
would nice if Resharper could offer a more functional conversion from
string to Int32 and vice versa, as an example.

int myValue = 3;
string s = myValue;
^-- should suggest "Convert.ToString() and myValue.ToString()"
string s = "3";
int myValue = s;
^-- should suggest "Convert.ToInt32()"
Other fixes might include "Enum.Parse" calls:

string s = "MyEnum";
MyEnum xx = s;
^-- should suggest Enum.Parse()
Most conversions have a "well-known" framework method to convert them.
It would be nice if Resharper exposed these.

Thanks!
Matt.



0

Please sign in to leave a comment.