IronPython对象的类型

2024-04-20 10:09:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于IronPython中对象类型的问题。我在C中创建了.NET类型(我创建了MyClass类),并编译了类库项目。假设我创造了测试库.dll以那种方式。然后我在我的IronPython项目中引用了这个库并创建了IronPython类,它继承了测试库.dll. 我的代码如下:

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

from TestLibrary import *

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

但是当我在TestPythonClass中创建一个对象时,我发现该对象的类型是'IronPython.NewTypes.TestLibrary.MyClass_15$16'。在

^{pr2}$

有谁能给我一些额外的信息,为什么我的IronPython对象的类型实际上是声明为的类型测试库.dll?为什么type不是TestPythonClass?在


Tags: 项目对象代码import类型net方式myclass
1条回答
网友
1楼 · 发布于 2024-04-20 10:09:15

IronPython使用反射来处理.NET类型。在

.GetType()方法从CLR调用类型。和打电话一样

clr.GetClrType(type(testPythonClass))

如果你打电话的话应该会有所不同

^{pr2}$

您将得到python类。在

相关问题 更多 >