[Python.NET] Casting an object to a different interface

Denis Akhiyarov denis.akhiyarov at gmail.com
Thu Feb 25 23:42:42 EST 2016


simple google search revealed this example from Bryan Lloyd for casting to
interface:

https://mail.python.org/pipermail/pythondotnet/2007-December/000753.html

Let us know if it works:

>* from mynamespace import Foo, Iface
*> >* inst = Foo() # create an instance
*> >* wrapped = Iface(inst) # 'cast' to the interface
*> >* wrapped.Func() # should now work*


On Tue, Feb 23, 2016 at 12:34 PM, Matthias Hillenbrand <mahibra at gmail.com>
wrote:

> Hi,
>
>
>
> The Python win32com module for accessing COM objects provides a method
> CastTo for casting an object to a different interface.
>
> Similarly, in my application, I have to cast an object to another .Net
> interface. Does  Python.Net provide such a method or can you describe a
> way of doing the casting using C# libraries?
>
>
>
> Here is a small example:
>
> I have an object of type ILDERow and want to cast it to
> ISurfaceCoordinateBreak. Using win32com this can be done in the following
> way:
>
> *from *win32com.client *import CastTo*
>
> cbSurface = CastTo(surface, *"ISurfaceCoordinateBreak"*)
>
>
>
> Thank you very much!
>
>
>
> Best regards,
>
> Matthias
>
>
>
>
>
>
>
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> https://mail.python.org/mailman/listinfo/pythondotnet
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20160225/c08347dc/attachment.html>


More information about the PythonDotNet mailing list