跨项目的部分类

发布于 2024-08-19 06:08:27 字数 87 浏览 2 评论 0原文

是否可以跨项目进行部分类。

例如,项目 1 有一个客户类别。 Project2 是一个可选模块,通过附加订单类并利用原始客户类来添加到客户类中。

Is it possible to have partial classes across projects.

e.g. Project 1 has a Customer Class.
Project2 which is an optional module adds to the customer class by attaching an order class, and utilising the original Customer Class.

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

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

发布评论

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

评论(4

落日海湾 2024-08-26 06:08:27

您不能使用 partial 关键字在项目之间拆分类的代码。 partial 关键字是一个编译器技巧;编译器将从它找到的部分中输出一个类,因此该类的所有部分必须存在于同一个二进制文件中。一旦类被编译,就不会留下它是分部类的痕迹。

如果您想扩展现有的类,您要么需要继承它(如果它没有密封),要么创建您自己的新类,其中包含您希望从中组合信息的类。

You cannot use the partial keyword to split the code for a class between projects. The partial keyword is a compiler trick; the compiler will output one single class out of the parts it finds, so all parts of the class must exist with the same binary file. Once the class is compiled, there is no trace left of it being a partial class.

If you want to extend an existing class you will either need to inherit it (if it is not sealed), or create your own new class that contains the classes that you wish to combine information from.

七分※倦醒 2024-08-26 06:08:27

不可以。分部类必须在相同的上下文(即程序集)中编译。

您可能想要做的是使用继承

No. A partial class must be compiled within the same context, i.e. assembly.

What you probably want to do is use Inheritance.

一腔孤↑勇 2024-08-26 06:08:27

分部类完全是一个编译器构造——它基本上将类定义连接在一起,然后进行编译。 .net 中没有“部分类”的概念,因此您不能将部分类拆分到不同的编译单元(项目或程序集)中

partial classes are entirely a compiler construct - it basically concatenates the class definitions together, then compiles that. There is no concept of a 'partial class' in .net, so you cannot split partial classes across different compilation units (projects or assemblies)

ι不睡觉的鱼゛ 2024-08-26 06:08:27

您不能在单独的项目中使用分部类。但是您可以使用扩展 类扩展或继承或接口

you can't use partial class in a separate projects.Period you can however use extensions Class Extensions or inheritance or interface

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