Find interfaces with single usage

Hi. Is there any possibility to find all interfaces in project which have only single usage?

Plot:
I have a quite large project, and I want to find dead code there. Usually we may rely on code inspect which shows unused classes and then one by one we can remove them

In this project some classes are implementing specific interface hierarchy and registered using reflection, dynamically, like

foreach (var type in Assembly.GetExecutingAssembly().GetTypes().OfType<ISomeInterface>())
{
    serviceCollection.AddScoped(type, typeof(ISomeInterface));
}

as a result, classes, implementing these interfaces, could be still in use, and only reliable reference here is how many usages of interface we currently have. If interface usage count is same as inheritance count, then we may say (with large ratio of confidence) that this interface is not used through code — at least we may check it.

Currently it is very hard to go manually through all interface declarations and check if this interface has same amount of usages as amount of inheritors.

Can I somehow do this in Rider?

0
1 comment

Hello Norrittmobile,

Regrettably, search does not support number of usages as a parameter. However, you can try Type dependency diagram - it might help with finding dead code in your case, depending on the specifics of your project.

0

Please sign in to leave a comment.