1
votes

I have a question about type of an object in IronPython. I've created .NET type in C# (I've created MyClass class) and compiled my class library project. Let's say I've created TestLibrary.dll in that kind of way. Then I referenced this library in my IronPython project and created IronPython class which inherits from .NET type which is in my TestLibrary.dll. My code looks like this:

import clr
clr.AddReferenceToFileAndPath(r'C:\TestLibrary\TestLibrary\bin\Debug\TestLibrary.dll')

from TestLibrary import *

class TestPythonClass(MyClass):
    def doSomething(self):
        print('Hello')

But when I created an object of my TestPythonClass I discovered that type of that object is 'IronPython.NewTypes.TestLibrary.MyClass_15$16'.

testPythonClass = TestPythonClass()
typeToString = testPythonClass.GetType().ToString()

Can anyone provide me with some additional information why type of my IronPython object is actually type which is declared into TestLibrary.dll? And why type is not the TestPythonClass?

1
The Python type and the .NET type of your object are different things. If you want the Python type, use the type function. - user2357112 supports Monica

1 Answers

2
votes

IronPython use the reflexion to handle .NET types.

The .GetType() method calls the type from CLR. Its the same as calling

clr.GetClrType(type(testPythonClass))

It should be different if you call

type(testPythonClass)

you will get the python class.