Is it possible to declare a partial class in two projects

后端 未结 4 1788
醉话见心
醉话见心 2021-01-17 16:02

Consider we create a partial class in Project1 and we have a Project2 that has reference to Project1 .How is it possible t

相关标签:
4条回答
  • 2021-01-17 16:03

    You can use the Extension methods that allow you to create additional methods for existing class

    0 讨论(0)
  • 2021-01-17 16:10

    It is not possible to extend a partial class in another project. Partial is only compiler sugar. The compiler will create only one class in the resulting assembly.

    0 讨论(0)
  • 2021-01-17 16:18

    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:

    • 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.
    0 讨论(0)
  • 2021-01-17 16:20

    Partial classes cannot exist out side assembly boundaries!

    0 讨论(0)
提交回复
热议问题