Automatically remove redundant type argument specifications during code cleanup

Is it possible to configure R# so that redundant type argument specifications are automatically removed during a code cleanup?

Eample:

var result = model.Bank
    .Select(p => p.Country)
    .Distinct()
    .ToList<Country>();

I want this to become automatically as part of a code cleanup this:

var result = model.Bank
    .Select(p => p.Country)
    .Distinct()
    .ToList();

4 comments

It should be removed.
Please could you provide complete example, where ReSharper fails to remove it?

0

I can't send you the complete solution but i tried it again in another line of code:

var list = model.Bank.Include(typeof(FinInstType).Name).Include(typeof(Country).Name).ToList<Bank>();

ReSharper correctly says that the <Bank> type argument is redundant but fails to remove it automatically. It is light gray coloured. I did a Full Cleanup and I selected the entire line and did a Full Cleanup again. It is not removed...

0

I created a new Class Library with this code and a full cleanup still won't remove the redundant type argument specification in GetAllHumanoids():

using System.Collections.Generic;
using System.Linq;
namespace ReSharperRedundantCodeCleanup
    public class HumanoidManager
        private readonly List<Humanoid> humanoids;
        public HumanoidManager()
            this.humanoids = new List<Humanoid>
                new Humanoid
                    Firstname = "John",
"Doe",
true
                new Humanoid
                    Firstname = "Jane",
"Doe",
false
            };
 
public List<Humanoid> GetAllMaleHumanoids()
            return this.humanoids.Where(humanoid => humanoid.IsMale = true).ToList<Humanoid>();
    }
    public class Humanoid
        public string Name { get; set; }
public string Firstname { get; set; }
public bool IsMale { get; set; }
}
0

Great! The problem is reproduced.
It will be fixed in ReSharper 5.0
Thank you.

0

Please sign in to leave a comment.