Andy E
Andy E

Reputation: 344733

How do I override a property in a non-inheritable class?

In the MSDN documentation, System.Reflection.Assembly has a property called CodeBase which is defined as overridable.

Public Overridable ReadOnly Property CodeBase As String

However, if I try to create a new class that inherits System.Reflection.Assembly, I get an error message that tells me it cannot be inherited. So how can I override this property?

Upvotes: 3

Views: 438

Answers (2)

Fredrik Mörk
Fredrik Mörk

Reputation: 158379

I don't think you can. While Assembly is not sealed (NotInheritable in VB.NET), it has no public constructor; the constructor is internal (Friend in VB.NET). So it can be inherited, but only of types within the same assembly as itself (which is mscorlib).

Upvotes: 3

LukeH
LukeH

Reputation: 269618

Unfortunately you can't do this.

Although the Assembly class itself is declared as public, it only provides an internal constructor. This effectively means that it can only be instantiated (or inherited) from within its own assembly, mscorlib.

Upvotes: 5

Related Questions