Interesting Tech Projects
Accessing an Overloaded C# Constructor from IronPython
The C# class ‘Foo’ has four constructors. The glue between IronPython and C# is not choosing the correct one. Here is how to force it.
import clr typ = clr.GetClrType(Foo) ctor = typ.GetConstructors()[3] newfoo = ctor.Invoke(System.Array[object](['string value', 1234]))
newfoo is now an instance of the Foo object, created using a string and int parameters. Here we are assuming the fourth constructor is the one we want, which isn’t very robust. Instead the constructors can be enumerated and the parameters evaluated to determine the correct constructor to use.
Print article | This entry was posted by Andy on May 14, 2019 at 7:50 am, and is filed under Software Engineering. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |
Comments are closed.