Friday 15 March 2013

c# - Override a virtual method in a partial class -


I am currently working with the source code and trying my best to avoid editing the source, But partial sections and plugins that are different from the source code, we must always need to upgrade the versions.

I want to make some changes to the legislation that holds an order using partial orbit in the same assembly:

Orignal source code:

  Namespaces: Nop.Services.Orders {Public Partial Class OrderProcessingService: IOrderProcessingService {Public Virtual PlaceOrderResult PlaceOrder (processPaymentRequest processPaymentRequest) {// ....   

My partial class:

  Named Location Nop.Services.Orders {Public Partial Class OrderProcessingService: IOrderProcessingService {Public Override PlaceOrderResult PlaceOrder (ProcessPaymentRequest processPaymentRequ Est) {// .. ..   

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

Type ' Nop.Services.Orde rs.OrderProcessingService defines the placeOrder '' with a single parameter type

already called a member 'but I override And using the method in the original class is virtual , can someone tell me where I am wrong and how can I override this method Not?

You can not override a virtual method in the same class. Partial orbits are split definitions in different places with only one class, so that simply is not possible, it does not define a hierarchy

This divides the definition of a class or a struct Is possible to do, or an interface on two or more source files. Each source file contains a class of square definition, and when all the parts are compiled the application is compiled

You should create a inherited class to achieve your goal

  Public category MyOrderProcessingService: OrderProcessingService {Public Override PlaceOrderResult PlaceOrder (processPaymentRequest processPaymentRequest) {// ....}    

No comments:

Post a Comment