Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to declare a partial class in two projects

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 ?

thanks

like image 568
Arian Avatar asked Dec 05 '11 10:12

Arian


1 Answers

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.
like image 90
Anders Abel Avatar answered Sep 24 '22 15:09

Anders Abel