抽象多个 C# 类

发布于 2024-12-08 08:53:27 字数 163 浏览 0 评论 0 原文

我必须处理一个项目,其中其他人复制并粘贴了同一个类大约 12 次,添加了一些自定义,但主要是,类的结构非常相似,因为它们是相互复制的。

我渴望重构代码,因为我无法忍受查看代码库。

有没有一种工具可以自动化解决一些令人头疼的问题,即将相同的属性和方法提取到父类中,并使其他类继承它?

I have to deal with a project where someone else has copied and pasted the same class some 12 times, added some customization, but mainly, the structure of the classes are really similar because they were copied from each other.

I am itching to refactor the code because I can't stand looking at the code base.

Is there a tool that can automate some of this headache, that is, extract identical properties and methods into a parent class and make the other classes inherit from it?

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

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

发布评论

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

评论(4

巾帼英雄 2024-12-15 08:53:27

与arivman类似,尝试一下Resharper。 30 天免费试用,每人可获得终身许可证(意味着可以将其带回家,也可以在他们允许的情况下从事其他工作)。

Similar to arivman, give Resharper a shot. 30 day free trial, life-time license available per person (means can take it back home, and to other jobs if they'll allow it).

心不设防 2024-12-15 08:53:27

我不知道任何免费的解决方案(除了自己做),但你可以提供 NET Refractor< /a> 来自 KnowDotNet 的截图。他们甚至还有 30 天的免费试用!

I don't know any free solution (other than doing it yourself), but you could give NET Refractor from KnowDotNet a shot. They even have a 30 day free trial!

冷默言语 2024-12-15 08:53:27

我还建议您在选择 Clone Detective 之类的工具https://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined/2807396#2807396">自然选择,可能有更加隐藏重复。

Resharper squigglies 肯定会给你一些关于代码味道和键盘组合的提示,然后立即修复。

您还可以使用此处的一些零碎内容 我个人发现分支和标记在这种情况下非常有效。我认为在深入研究代码之前进行的任何分析尽职调查也大有帮助。

I'd also recommend you to use a tool like Clone Detective before you opt for the Natural selection, there might be more hidden duplication.

Resharper squigglies will definitely give you some hints about code smells and keyboard combos to fix then in a jiffy.

You could also potentially use some bits and pieces from here and i personally find branching and tagging to be quite effective in situations like these. Any analytical due diligence prior to delving in the code i think goes a long way too.

☆獨立☆ 2024-12-15 08:53:27

这里我们使用 simian 来查找重复的代码。但同样,您仍然需要手动干预 2 删除或 2 更新它。

Here we use simian to find the duplicate code. But again you still need manual intervention 2 remove or 2 update it.

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