是否有可能在两个项目申报分部类部类、有可能、项目申报、两个

2023-09-03 05:16:18 作者:夜久泪长

考虑,我们在创建一个部分类的 PROJECT1 ,然后我们有一个 Project2的有参考 PROJECT1 。如何才有可能宣布一些部分类的其他方法的 Project2的

Consider we create a partial class in Project1 and we have a Project2 that has reference to Project1 .How is it possible to declare some other method of partial class in Project2 ?

感谢

推荐答案

局部构造仅仅是一个编译器的功能,允许类为s $ P $垫在几个源文件。编译的类仍然生活在一个且只有一个类库(DLL文件)。

The partial construct is only a compiler functionality, to allow a class to be spread out in several source files. The compiled class still lives in one and only one class library (dll file).

有两种方法来扩展类在另一个库:

There are two ways to extend a class in another library:

在继承,除非类是密封。这需要调用code处理所有的对象实例来实例化新的派生类。 扩展方法,这使得code样子有该类的新方法,但这只是语法糖。它不会改变类本身。 Inheritance, unless the class is sealed. This requires that the calling code handles all object instantiation to instantiate the new derived class. Extension methods, which makes the code look like there are new methods on that class, but that is just syntactic sugar. It won't change the class itself.