Override a virtual method in a partial class

前端 未结 5 775
暗喜
暗喜 2021-01-18 01:47

I am currently working with the nopCommerce source code and trying my best to avoid editing the source at all, but instead using partial classes and plugins that are separat

5条回答
  •  Happy的楠姐
    2021-01-18 02:24

    You can't do that. What partial basically does is tell the C# compiler to join the two bits of code together.

    A bit of a hacky solution is to finish off the class, and then inherit from that and override the methods you want, e.g. here's a simple example:

    public partial class A
    {
        public virtual void X() { }
    }
    public partial class A
    {
        public void Y() { }
    }
    public class B : A
    {
        public override void X() { }
    }
    

提交回复
热议问题