Description
I have a C# class, lets call it MyCSClass, that I intend to be inherited from a Python class and used like this:
class MyPythonClass(MyCSClass):
def __init__(self):
self.MyAttribute = 5
self.Callback(self)
When an instance of MyPythonClass gets passed to C#, it gets converted to a MyCSClass and is stripped of all the attributes. Even if the method called in CS takes it as a dynamic or PyObject. An example of this could be the init method above calling into the following C# code:
public class MyCSClass {
protected void Callback(dynamic self){
Console.WriteLine("A dynamic attribute: {0}", self.MyAttribute);
}
}
However, the instance assigned to 'self' is an MyCSClass and not a dynamic MyPythonClass. Replace dynamic
with PyObject
and you get an exception. If suggest the the converter should support PyObject, so that callbacks like these are made possible.
Then I would have to do this instead, which is OK for me:
public class MyCSClass {
protected void Callback(PyObject self){
Console.WriteLine("A dynamic attribute: {0}", ((dynamic)self).MyAttribute);
}
}
Python Version: Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
OS: Windows 7 Enterprise