views:

1090

answers:

1

I have a class split across two files. One of these is generated, the other contains the non-generated stuff.

I want my class to inherit from a base class. Do I need to have both files inherit? Or will the class inherit from the base class if either partial class

In generated foo.vb:

Partial Public Class Foo Inherits BaseClass

In manually-created foo.vb:

Partial Public Class Foo

It doesn't seem to matter (according to what I see in Reflector, anyways).

Can anyone explain how this works? Does the compiler simply combine the two?

+7  A: 

Only one of the two needs to inherit.

Partial classes are just compiler tricks. Your two files are stitched back together before compiling. This means that only one base class can be specified, just like in normal classes.

You can have this:

partial class one : base {}
partial class one {}

and this:

partial class one : base {}
partial class one : base {}

but not this

partial class one : fu {}
partial class two : bar {}

because the last one combines into:

class one : fu, bar {}

which is illegal. You can mix and match interfaces, however, just like on a normal class.

Will