告诉 Resharper 使用 spring.net DI 配置来检查未使用的类?

发布于 2024-10-04 13:16:31 字数 809 浏览 0 评论 0原文

当我的部分代码从未被使用时,Resharper 会发出警告;这非常有帮助。

但是,我有很多类没有被其他代码直接引用。这些类仅在依赖项注入 (DI) 配置中使用。

我使用 spring.net 进行 DI。 DI 配置为 xml 格式。

有什么方法可以告诉 Resharper 使用 DI 文件来检查未使用的类吗?

我知道我可以使用类似以下内容来抑制 Resharper 警告:

// ReSharper disable UnusedMember.Global
public class TheClass : IInterfaceWiredUsingSpringDI
// ReSharper restore UnusedMember.Global

但我不太喜欢这个 - 它很难阅读,而且我真的不想抑制警告。

注意:

有一种不那么唐突且更具可读性的方法来抑制警告,我在 jetbrains 论坛。当您定义此自定义属性时:

[MeansImplicitUse]
public class IoCAttribute : Attribute { }

然后您可以抑制警告:

[IoC]
public class TheClass : IInterfaceWiredUsingSpringDI 

Resharper warns me when parts of my code are never used; this is very helpful.

However, I have quite a few classes that are not referenced by other code directly. These classes are used in the dependency injection (DI) configuration only.

I use spring.net for DI. The DI configuration is in xml format.

Is there any way I can tell Resharper to use the DI files for the inspection of unused classes?

I know I can suppress the Resharper warning using something like:

// ReSharper disable UnusedMember.Global
public class TheClass : IInterfaceWiredUsingSpringDI
// ReSharper restore UnusedMember.Global

But I don't like this very much - it's difficult to read and I don't really want to suppress the warning.

Note:

There is a less obtrusive and more readable way to suppress the warning, which I found on the jetbrains forum. When you define this custom attribute:

[MeansImplicitUse]
public class IoCAttribute : Attribute { }

Then you can suppress the warning:

[IoC]
public class TheClass : IInterfaceWiredUsingSpringDI 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌梦深 2024-10-11 13:16:31

我已经晚了 3 年才回答这个问题,但我刚刚通过 ReSharper 的 Twitter 流看到了这个问题。我为 ReSharper 创建了一个名为 Agent Mulder 的插件,它的作用完全一样这——分析 IoC 容器注册,并允许导航和查找通过容器注册的类型的用法!

有关受支持容器的列表,请访问该项目的 wiki 在 github 上。

(不幸的是,它不适用于 Spring.NET,因为没有需求,抱歉:))

I'm 3 years too late to answer this, but I just saw this question via ReSharper's twitter stream. I created a plugin for ReSharper called Agent Mulder, and it does exactly this -- analyzes IoC container registrations, and allows navigating and finding usages of types that are registered via the container!

For the list of supported containers, please visit the project's wiki on github.

(Unfortunately, it doesn't work with Spring.NET, since there was no demand for it, sorry :))

平安喜乐 2024-10-11 13:16:31

我不相信是这样。花了一些时间尝试用 IOC 和 ReSharper 解决类似的问题,但没有成功,据我所知,这并不能促进解决问题。

I don't believe so. Spent a bit of time trying to solve a similar frustration with IOC and ReSharper to no avail, just doesn't facilitate it as far as I can tell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文