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.
Note: available since IronPython 2.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With