@@ -1402,6 +1402,35 @@ def call_method_with_enum():
14021402 Assert . AreEqual ( DayOfWeek . Monday , CSharpModel . ProvidedArgument ) ;
14031403 }
14041404
1405+ [ TestCase ( "call_non_generic_method" , "GenericOverloadTestMethod" ) ]
1406+ [ TestCase ( "call_generic_method" , "GenericOverloadTestMethod<T>" ) ]
1407+ [ TestCase ( "call_generic_class_method" , "GenericOverloadTestClass<T>.GenericOverloadTestMethod" ) ]
1408+ public void ResolvesToGenericOnlyWhenExplicitlyCalled ( string pythonFuncToCall , string expectedMethodCalled )
1409+ {
1410+ using var _ = Py . GIL ( ) ;
1411+
1412+ var module = PyModule . FromString ( $ "ResolvesToGenericOnlyWhenExplicitlyCalled_{ pythonFuncToCall } ", @$ "
1413+ from clr import AddReference
1414+ AddReference(""System"")
1415+ from Python.EmbeddingTest import *
1416+
1417+ def call_non_generic_method():
1418+ return TestMethodBinder.CSharpModel.GenericOverloadTestMethod(TestMethodBinder.CSharpModel(), 'Test')
1419+
1420+ def call_generic_method():
1421+ return TestMethodBinder.CSharpModel.GenericOverloadTestMethod[TestMethodBinder.CSharpModel](TestMethodBinder.CSharpModel(), 'Test')
1422+
1423+ def call_generic_class_method():
1424+ return GenericOverloadTestClass[TestMethodBinder.CSharpModel].GenericOverloadTestMethod(TestMethodBinder.CSharpModel(), 'Test')
1425+ " ) ;
1426+
1427+ Assert . DoesNotThrow ( ( ) =>
1428+ {
1429+ using var result = module . GetAttr ( pythonFuncToCall ) . Invoke ( ) ;
1430+ } ) ;
1431+ Assert . AreEqual ( expectedMethodCalled , CSharpModel . LastFuncCalled ) ;
1432+ }
1433+
14051434 // Used to test that we match this function with Py DateTime & Date Objects
14061435 public static int GetMonth ( DateTime test )
14071436 {
@@ -1636,6 +1665,18 @@ public static void TestAction3(CSharpModel model1, CSharpModel model2)
16361665 }
16371666 LastFuncCalled = "TestAction3" ;
16381667 }
1668+
1669+ public static string GenericOverloadTestMethod ( CSharpModel testArg1 , string testArg2 , decimal testArgs3 = 0m )
1670+ {
1671+ LastFuncCalled = "GenericOverloadTestMethod" ;
1672+ return string . Empty ;
1673+ }
1674+
1675+ public static T GenericOverloadTestMethod < T > ( CSharpModel testArg1 , string testArg2 , decimal testArgs3 = 0m )
1676+ {
1677+ LastFuncCalled = "GenericOverloadTestMethod<T>" ;
1678+ return default ;
1679+ }
16391680 }
16401681
16411682 public class TestImplicitConversion
@@ -1784,4 +1825,14 @@ public enum SomeEnu
17841825 B = 2 ,
17851826 }
17861827 }
1828+
1829+ public class GenericOverloadTestClass < T >
1830+ {
1831+ public static T GenericOverloadTestMethod ( T testArg1 , string testArg2 , decimal testArgs3 = 0m )
1832+ {
1833+ TestMethodBinder . CSharpModel . LastFuncCalled = "GenericOverloadTestClass<T>.GenericOverloadTestMethod" ;
1834+ return default ;
1835+
1836+ }
1837+ }
17871838}
0 commit comments