[Python.NET] "Incorrect" behavior of inheriting from class which is inherited from .Net class

Hansong Huang hhspiny at live.com
Sun Apr 10 22:30:08 EDT 2016


Hello,
This is related to previous investigation of inheriting from .NET interface class to create WPF MVVM structure.  As now I believe it has nothing to do with interface class, but instead caused by inheriting from .Net class overall. 
please see the following code
import clr, Systemclass baseNA(System.Random):    __namespace__ = "BaseNA"    def __init__(self):        super(baseNA,self).__init__()#    @clr.clrmethod(System.String,[])    def ToString(self):        return "string"
class baseNB(baseNA):    __namespace__ = "BaseNB"    def __init__(self):        super(baseNB,self).__init__()bna = baseNA()print bna.ToString()print bna._Random__ToString()bnb = baseNB()print bnb.ToString()print bnb._baseNA__ToString()print bnb._Random__ToString()

This produces the following outputstringBaseNA.baseNABaseNB.baseNBBaseNB.baseNBBaseNB.baseNB
as you see, while baseNA -- the first level inherited class works fine. ToString() overrides System.Random.ToString()
But baseNB inherited from baseNA did not inherit ToString() method from baseNA, but rather inherited from System.Random.  
Not sure if it is a bug in python.net or was intended. 
regards,
Hansong



 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20160410/0b1a674b/attachment.html>


More information about the PythonDotNet mailing list