can you typecast a .NET object in IronPython?

前端 未结 4 2147
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:05

    clr.Convert doesnt exist in IronPython 2.0 . This is not a solution to typecast a .NET object in IronPython?, but it's a workaround to convert the data if you really need it to use it from IronPython

    Create a class like this in VB.NET and compile it into a DLL

    Imports Microsoft.VisualBasic
    
        Public Class MyConvert
    
            Shared Function converttype(ByVal value As String) As Integer
                Return CInt(value)
            End Function
    
        End Class
    

    Then in IronPython you do

    clr.AddReference('MyConvert')
    from MyConvert import converttype         
    converted_value = converttype("2.0")
    

提交回复
热议问题