我所在的项目有很多部分类(意味着使用了关键字“部分”),但我不知道它们是否真的偏向任何东西(我希望编译器会寻找另一个partial(s) 并且如果没有找到则抛出错误但事实是它不会抛出导致我提出问题的错误)。
因为我无法判断创建分部类时它是否具有其他“分部”,所以我想到分部必须在同一个程序集中?是否可以通过 WCF 或 Web 服务在程序集外部创建部分类 - 我不知道它在运行时如何工作(我猜编译器会满意,因为它似乎不太关心)但我找不到任何明确说明是或否的内容。 Similar questions解释它不应该以这种方式使用,但如果可以或不能,则不能。
请您参考如下方法:
would the partial(s) have to be within the same assembly?
是的,他们必须如此。这是部分规范的一部分 - 所有部分都必须在一个程序集中。
Would it be possible to create a partial class outside an assembly via WCF or a web service
不——那是不可能的。
来自 C# 4.0 语言规范的 §10.2:
All parts of a partial type must be compiled together such that the parts can be merged at compile-time into a single type declaration.
