can you typecast a .NET object in IronPython?

前端 未结 4 2129
Happy的楠姐
Happy的楠姐 2021-01-05 07:35

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

4条回答
  •  时光说笑
    2021-01-05 08:29

    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.

    Note: available since IronPython 2.6.

提交回复
热议问题