@@ -805,6 +805,34 @@ public string ImplicitConversionSameArgumentCount2(string symbol, decimal quanti
805805 {
806806 return "ImplicitConversionSameArgumentCount2 2" ;
807807 }
808+
809+ // ----
810+
811+ public string VariableArgumentsMethod ( params CSharpModel [ ] paramsParams )
812+ {
813+ return "VariableArgumentsMethod(CSharpModel[])" ;
814+ }
815+
816+ public string VariableArgumentsMethod ( params PyObject [ ] paramsParams )
817+ {
818+ return "VariableArgumentsMethod(PyObject[])" ;
819+ }
820+
821+ public string ConstructorMessage { get ; set ; }
822+
823+ public OverloadsTestClass ( params CSharpModel [ ] paramsParams )
824+ {
825+ ConstructorMessage = "OverloadsTestClass(CSharpModel[])" ;
826+ }
827+
828+ public OverloadsTestClass ( params PyObject [ ] paramsParams )
829+ {
830+ ConstructorMessage = "OverloadsTestClass(PyObject[])" ;
831+ }
832+
833+ public OverloadsTestClass ( )
834+ {
835+ }
808836 }
809837
810838 [ TestCase ( "Method1('abc', namedArg1=10, namedArg2=321)" , "Method1 Overload 1" ) ]
@@ -898,6 +926,75 @@ def call_method(instance):
898926 Assert . IsFalse ( Exceptions . ErrorOccurred ( ) ) ;
899927 }
900928
929+ [ Test ]
930+ public void BindsConstructorToSnakeCasedArgumentsVersion ( [ Values ] bool useCamelCase , [ Values ] bool passOptionalArgument )
931+ {
932+ using var _ = Py . GIL ( ) ;
933+
934+ var argument1Name = useCamelCase ? "someArgument" : "some_argument" ;
935+ var argument2Name = useCamelCase ? "anotherArgument" : "another_argument" ;
936+ var argument2Code = passOptionalArgument ? $ ", { argument2Name } =\" another argument value\" " : "" ;
937+
938+ var module = PyModule . FromString ( "BindsConstructorToSnakeCasedArgumentsVersion" , @$ "
939+ from clr import AddReference
940+ AddReference(""System"")
941+ from Python.EmbeddingTest import *
942+
943+ def create_instance():
944+ return TestMethodBinder.CSharpModel({ argument1Name } =1{ argument2Code } )
945+ " ) ;
946+ var exception = Assert . Throws < ClrBubbledException > ( ( ) => module . GetAttr ( "create_instance" ) . Invoke ( ) ) ;
947+ var sourceException = exception . InnerException ;
948+ Assert . IsInstanceOf < NotImplementedException > ( sourceException ) ;
949+
950+ var expectedMessage = passOptionalArgument
951+ ? "Constructor with arguments: someArgument=1. anotherArgument=\" another argument value\" "
952+ : "Constructor with arguments: someArgument=1. anotherArgument=\" another argument default value\" " ;
953+ Assert . AreEqual ( expectedMessage , sourceException . Message ) ;
954+ }
955+
956+ [ Test ]
957+ public void PyObjectArrayHasPrecedenceOverOtherTypeArrays ( )
958+ {
959+ using var _ = Py . GIL ( ) ;
960+
961+ var module = PyModule . FromString ( "PyObjectArrayHasPrecedenceOverOtherTypeArrays" , @$ "
962+ from clr import AddReference
963+ AddReference(""System"")
964+ from Python.EmbeddingTest import *
965+
966+ class PythonModel(TestMethodBinder.CSharpModel):
967+ pass
968+
969+ def call_method():
970+ return TestMethodBinder.OverloadsTestClass().VariableArgumentsMethod(PythonModel(), PythonModel())
971+ " ) ;
972+
973+ var result = module . GetAttr ( "call_method" ) . Invoke ( ) . As < string > ( ) ;
974+ Assert . AreEqual ( "VariableArgumentsMethod(PyObject[])" , result ) ;
975+ }
976+
977+ [ Test ]
978+ public void PyObjectArrayHasPrecedenceOverOtherTypeArraysInConstructors ( )
979+ {
980+ using var _ = Py . GIL ( ) ;
981+
982+ var module = PyModule . FromString ( "PyObjectArrayHasPrecedenceOverOtherTypeArrays" , @$ "
983+ from clr import AddReference
984+ AddReference(""System"")
985+ from Python.EmbeddingTest import *
986+
987+ class PythonModel(TestMethodBinder.CSharpModel):
988+ pass
989+
990+ def get_instance():
991+ return TestMethodBinder.OverloadsTestClass(PythonModel(), PythonModel())
992+ " ) ;
993+
994+ var instance = module . GetAttr ( "get_instance" ) . Invoke ( ) ;
995+ Assert . AreEqual ( "OverloadsTestClass(PyObject[])" , instance . GetAttr ( "ConstructorMessage" ) . As < string > ( ) ) ;
996+ }
997+
901998
902999 // Used to test that we match this function with Py DateTime & Date Objects
9031000 public static int GetMonth ( DateTime test )
@@ -918,6 +1015,12 @@ public CSharpModel()
9181015 new TestImplicitConversion ( )
9191016 } ;
9201017 }
1018+
1019+ public CSharpModel ( int someArgument , string anotherArgument = "another argument default value" )
1020+ {
1021+ throw new NotImplementedException ( $ "Constructor with arguments: someArgument={ someArgument } . anotherArgument=\" { anotherArgument } \" ") ;
1022+ }
1023+
9211024 public void TestList ( List < TestImplicitConversion > conversions )
9221025 {
9231026 if ( ! conversions . Any ( ) )
0 commit comments