ironpython2 icon indicating copy to clipboard operation
ironpython2 copied to clipboard

Method "Overloads"

Open GLantaff opened this issue 5 years ago • 1 comments

Using IronPython 2.7.9

Using the "Explicitly-implemented interface" method to call methods defined by an interface usually works fine. I now have a case where the stupid interface has duplicate methods with different argument types (in this case, two diferent interfaces). My object has both interfaces defined so I need to tell python which method to call. The "Overloads" method trick does not work using interfaces. If something like "IDoSomething.MyMethod.Overloads[IFoo1](myObj, arg1)" could be added that would be great.

GLantaff avatar Dec 04 '18 17:12 GLantaff

As posted by @GLantaff on gitter, a workaround for this is to use Reflection, for example:

types = Array[Type]([clr.GetClrType(IFoo), clr.GetClrType(IFoo2)])
method = clr.GetClrType(IDuplicator).GetMethod("Duplicate", types, None)
method.Invoke(duplicator, Array[Object]([arg1, arg2]))

slozier avatar Dec 05 '18 15:12 slozier