开发者

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

In the MSDN documentation, S开发者_运维技巧ystem.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?


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜