How to invoke (non virtually) the original implementation of a virtual method?

后端 未结 4 1144
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 01:20

I have the following situation:

In a 3rd party library (can not be modified):

class A { public virtual void M() {} }

class B : A { public override v         


        
4条回答
  •  借酒劲吻你
    2020-12-18 01:43

    In my previous answer I missed the fact that A and B are in an external library and cannot be modified. In that case, I would suggest a different approach. Basically, if the design flaw is in B, you can’t use B. Subclass from A instead.

    The unfortunate consequence of this, of course, is that you may need to reimplement some or all of the functionality in B. You may be able to copy the code from Reflector if necessary. I realise that this sounds undesirable, but I still think it is preferable to using unmodifiable code that has a known issue that causes you problems.

提交回复
热议问题