是否有可能在两个项目申报分部类 [英] Is it possible to declare a partial class in two projects

查看:148
本文介绍了是否有可能在两个项目申报分部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑,我们在创建一个部分类的 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.

这篇关于是否有可能在两个项目申报分部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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