Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can you typecast a .NET object in IronPython?

Tags:

ironpython

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.

like image 209
Phil Smyth Avatar asked Sep 17 '09 15:09

Phil Smyth


1 Answers

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.

like image 186
Dino Viehland Avatar answered Oct 14 '22 21:10

Dino Viehland