为什么要使用部分类? [英] Why use partial classes?

查看:95
本文介绍了为什么要使用部分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的部分类和想知道,如果有人可以给我为什么我会使用它们,什么好处我将获得在这个过程中的大画面。

I am new to partial classes and was wondering if someone could give me a "big picture" of why I would use them and what advantage I would gain in the process.

推荐答案

部分类的最大用途是使生活更轻松的code发电机/设计师。部分类允许生成简单地发出code,他们需要发出,并且没有处理用户编辑该文件。用户同样是通过自由具有第二部分类注释与新成员的类。这提供了分离关注一个非常干净的框架。

The biggest use of partial classes is make life easier on code generators / designers. Partial classes allow the generator to simply emit the code they need to emit and do not have to deal with user edits to the file. Users are likewise free to annotate the class with new members by having a second partial class. This provides a very clean framework for separation of concerns.

有一个更好的方式来看待它是看设计师局部类之前如何运作。该设计师的WinForms会吐出所有的code的区域内有关不修改code措辞强硬的评论。它必须插入各种启发式找到产生code稍后处理。现在,它可以简单地打开designer.cs文件,并具有较高的可信度,它仅包含$ C相对于设计师$ C。

A better way to look at it is to see how designers functioned before partial classes. The WinForms designer would spit out all of the code inside of a region with strongly worded comments about not modifying the code. It had to insert all sorts of heuristics to find the generated code for later processing. Now it can simply open the designer.cs file and have a high degree of confidence that it contains only code relative to the designer.

这篇关于为什么要使用部分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆