[QUESTION] CodeInspect - Hint for smallest possible Interface

Answered

Hejj everyone,

I use Rider (C#) for some time now and really love the code insprector hinting code improvements according to my settings.
Lately I started to use the smallest possible interface whenever serving a public field, i.e. replacing a List<T> with IReadOnlyCollection<T> when data shall only be read but not writting from external souces. 

I wonder if it somehow is possible to setup Rider to assist me in that regard? Searching in the settings and google didn't help me so far.
It would be very helpful if Rider tells me, whenever I can use the interface of an object instead the actual implementation, i.e. because I only use the interface methods (and none of the actual implementation). 

Any hint is much appreciated! 
Cheers,
Christian 

0
3 comments

Hello Christian Bvf, thank you for your question.

Please take a look at Use Base Type Where Possible refactoring. Does it help you to do what you need?

Thank you!

1

Hello Maria Pleskunina

Thanks for your reply, which is helpful already. 
However, it would be even more helpful if Rider could hint a possible replacement already?
For example in the following example it would be nice, if Rider highlights the 'Tester' type, telling me there is a base class that I can use. 

public class Test
{
private Tester myTester = new Tester();

public void Foo()
{
myTester.DoSomething();
}
}

public interface ITester
{
public void DoSomething();
}

public class Tester : ITester
{
public void DoSomething() {}
}

Do you know if this is possible? 

0

Christian Bvf, thanks for the idea and sorry for the late response.

I've submitted a new feature request to our bug tracker. Please comment or vote for it to get notifications about status changes. Thank you!

 

0

Please sign in to leave a comment.