views:

407

answers:

1

I have two classes A and B in two different .NET assemblies: AssemblyA and AssemblyB.

I want class B to inherit class A but I want that however uses class B to only need to reference AssemblyB (and not both AssemblyA and AssemblyB).

Due to the project constraints I need to keep the two assemblies separate so I cannot use merge tool to merge the two assemblies.

Note that actual inheritance of classes is not a must - I want to be able to have logic from A run in AssemblyB as part of class B with as little as possible rewriting of functionality.

Is there a way to accomplish this?

+8  A: 

No. Think of it in this way - suppose youI type in the following:

public class B : A
{
      public void Foo()
      {
            this.// Cursor is here
      }
}

How do you expect Intellisense to know what's available if it doesn't know what's in class A? How would the compiler be able to validate method calls etc?

You have to know about the parent classes all the way up the inheritance chain. This means referencing both projects. If you don't want to do this, don't use inheritance - make B compose A instead of deriving from it. Users will still need the binary for A available at execution time, but I don't think they'll need to add a reference in Visual Studio. (On the other hand, if they're going to debug the code, they'll probably want to anyway to make sure the binary is in the right place...)

Jon Skeet