can you typecast a .NET object in IronPython?

前端 未结 4 2163
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:16

    I had a similar problem on a project a few months ago. This was my fix:

    import clr
    
    clr.GetPythonType(x)
    

    x can be a .NET type or a type that is in a dll file that you have imported using clr.

    I am not a C# programmer, but I have been told by C# programmer colleagues that this code in C# would be:

    typeof(x)
    

    Hope this helps

提交回复
热议问题