可以在IronPython中键入.NET对象吗? [英] can you typecast a .NET object in IronPython?
问题描述
我正在与IronPython中的.NET API交互. API返回的对象类型错误(某种通用对象).我怀疑问题没有出现在他们的C#代码中,因为构造对象时的类型声明迫使返回的对象为正确的类型.是否可以在IronPython中对.NET对象进行类型转换?我认为这可以解决问题.
I'm interfacing with a .NET API in IronPython. The API is returning an object of the wrong type (some kind of generic object). I suspect that the problem is not showing up in their C# code because the type declaration when the object is constructed is forcing the returned object to the correct type. Is it possible to typecast an .NET object in IronPython? I think this would do the trick.
推荐答案
要强制进行转换,您可以执行以下操作:
To force a conversion you can do:
import clr
convertedObject = clr.Convert(someObject, someType)
这将搜索并运行隐式/显式转换(如果存在).
This will search for and run implicit/explicit conversions if one exists.
注意:自IronPython 2.6起可用.
Note: available since IronPython 2.6.
这篇关于可以在IronPython中键入.NET对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!