Skip to content

Derived class in Python not being called by C# #1107

Description

@jeffzi19

Hello - this is my first post so apologies if this is the wrong forum.

I'm trying to define a base class in C# and derive from that class in python / pythonnet. The C# class is very basic:

    public class Order
    {
        public string symbol;

        public virtual void Evaluate( Bar b )
        {
            Console.WriteLine( "from Order.Evaluate() - hello!" );
        }
    }

In python I have the specific order class defined as:

class LimitOrder(Order):

    def __init__(self):
        self.symbol = "SQ"


    def Evaluate( self, bar ):
        print( "LimitOrder.Evaluate() - yay python!" )

In C# I have an OMS class with a method: public void AddOrder( Order order )

When I pass in LimitOrder and call a method in the OMS that calls Evaluate, the Order class Evaluate method is called instead of the LimitOrder.Evaluate method.

I'm using python 3.6.7 and VS 2019 / .NET 4.7.2

In searching for this I'm only seeing 1 instance of a similar question being asked but no solid response. The Evaluate() method (and entire Order class for that matter) can be abstract but when I try that I get an error creating the LimitOrder object saying I can't create an abstract class.

Any help would be appreciated. Thanks in advance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions