Alex Rivera | Logout

Override a virtual method in a partial class

Asked 2013-06-21T17:33:38.803
15

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 separate from the source code, should we ever need to upgrade versions.

I want to make some changes to the code that places an order, by using a partial class in the same assembly:

Orignal Source Code:

namespace Nop.Services.Orders {

  public partial class OrderProcessingService : IOrderProcessingService {

        public virtual PlaceOrderResult PlaceOrder(ProcessPaymentRequest processPaymentRequest)
        { //....

My partial class:

namespace Nop.Services.Orders {

  public partial class OrderProcessingService : IOrderProcessingService {

    public override PlaceOrderResult PlaceOrder(ProcessPaymentRequest processPaymentRequest) { //....

When I try to compile this code I get an error:

Type 'Nop.Services.Orders.OrderProcessingService' already defines a member called 'PlaceOrder' with the same parameter types

But I am using override and the method in the original class is virtual, could someone tell me where I am going wrong here, and how I could override this method?

Edit
Report

1 Answer

3

You can use partial class to split the code of a class in multiple, but you can not split a single method in 2 partial classes. You need to have method in only one place. If you want to extent the functionality then look for another methods like sub-classing or composition etc. which ever suits your scenario.

answered 2013-06-21T17:38:44.080

Your Answer