ironpython2
ironpython2 copied to clipboard
Method "Overloads"
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.
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]))