重构部分类 - 指南
我正在处理 ASP.NET 用户控件的大量代码隐藏。我正在采用将庞大的类重构为许多按 UI 意图分隔的部分类的方法。
是否有关于以下方面的指导:
我必须限制自己参加的部分课程的数量。
为部分类文件指定的命名或名称。
I am dealing with a huge codebehind of a an ASP.NET user control. I am taking the approach of refactoring the huge class into a number of partial clasees separted by UI intent.
Is there guidance on:
Number of partial classes I am must constrain myself to.
Naming or names to be given toof the partial class files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用的部分类文件的数量没有限制。它们在编译时都编译成一个类。但是,部分类文件越多,当尝试在类中查找不同功能时,事情可能就越混乱。
我将以类名开头命名文件,然后跟踪文件所解决的问题。这样您就可以更清楚地了解每个文件中的内容。
你也应该小心你的班级。如果一个类正在解决几个不同的 UI 问题,以至于您认为应该将其分成单独的文件,那么听起来您的类应该分解为几个更小、更简洁的类(而不是跨多个文件定义的单个整体类) )。
There's no limit to the number of Partial Class files you can use. They all compile into a single class at compile time. The more partial class files, though, the more confusing things could be when trying to find different functionality in the class.
I would name the files starting with the class name and then follow up with which concern the file was addressing. That way you're a little more clear about what is in each file.
You should also be careful about your class. If a single class is addressing several different UI Concerns to the point that you feel it should be separated into separate files it sounds like your class should be broken up into several smaller, more concise classes (rather than a single monolithic class defined across several files).
我不熟悉部分课程的限制。
关于文件命名,再次强调 - 没有限制。它可以是任何东西。
我个人的偏好是[MainClassName].[aspect].cs,
例如:MyHugeControl.Reports.cs、MyHugeControl.Data.cs等。
I'm not familiar with a partial classes limitation.
About file naming, again - no limitation. It could be anything.
My personal preference would be [MainClassName].[aspect].cs,
for example: MyHugeControl.Reports.cs, MyHugeControl.Data.cs, etc.