0

I have a partial Class "ClassA" in an assembly MyAssembly.

Can I extend this partial class in a separate assembly "MyExtendedAssembly" with the same name "ClassA"

When partial classes are not possible in a separate assembly, is there any other way where we can extend the properties without inheritance?

Thanks

8
  • 1
    Have you tried it? This seems to be a question that you could very easily find out the answer to yourself.
    – Jashaszun
    Jul 28, 2015 at 19:57
  • 2
    I googled your exact question header and came up with this: stackoverflow.com/questions/3858649/… Jul 28, 2015 at 19:58
  • 1
    Why would you want to do this? What problem are you trying to solve?
    – crush
    Jul 28, 2015 at 19:58
  • How was this upvoted? :/
    – Jashaszun
    Jul 28, 2015 at 19:58
  • @Jashaszun Tried, it didn't work. Trying if there are any ways to achieve this.
    – Satyajit
    Jul 28, 2015 at 19:59

2 Answers 2

3

No, partial classes must be in the same assembly. They are only partial in source code. When the code is compiled the compiler finds all the partial parts and combines them at compile time into a single class.

The runtime has no concept of a partial class, only the compiler.

2
  • Thanks. Are there any ways similar thing can be achieved?
    – Satyajit
    Jul 28, 2015 at 20:00
  • @user1731788, yes, you need some kind of plugin system. Declare an interface that has the methods you want to call, then use reflection to find any implementations and call them. Use properties or whatever on the interface to pair up calling and callee classes. The code we use for finding assignable classes is posted here: stackoverflow.com/questions/2159879/… Jul 28, 2015 at 20:37
1

use extension and interface if you dont like inhertance. Partial class are mean to be together in one assembly like a partner in a family. ^^,

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.