dotnet / roslyn-analyzers

MIT License
1.59k stars 466 forks source link

Analyzer to Remove Unnecessary System.Convert #3326

Open vsfeedback opened 4 years ago

vsfeedback commented 4 years ago

This issue has been moved from a ticket on Developer Community.


An analyzer should detect cases where type X is passed into the System.Convert.ToX method and suggest removing the Convert invocation.

In the following sample code System.Convert.ToBoolean is useless and should be removed.

namespace N
{
    public static class C
    {
        public static bool M()
        {
            bool value = true;
            return System.Convert.ToBoolean(value);
        }
    }
}

Original Comments

Visual Studio Feedback System on 2/16/2020, 05:37 AM:

Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We'll provide an update once the issue has been triaged by the product team.

Evangelink commented 4 years ago

I guess the idea would be to handle only the object overload. I am not sure how valuable this rule will be though. I guess it could probably be part of the unnecessary cast analyzer, wdyt @mavasani ?

mavasani commented 4 years ago

Yes, let us see if we get any more feedback or user requests for this analyzer.