@@ -709,6 +709,93 @@ public int another_int_property()
709709 {
710710 return 654 ;
711711 }
712+
713+ public virtual int get_value ( int x )
714+ {
715+ throw new Exception ( "get_value(int x)" ) ;
716+ }
717+
718+ public virtual int get_value_2 ( int x )
719+ {
720+ throw new Exception ( "get_value_2(int x)" ) ;
721+ }
722+
723+ public int get_value_3 ( int x )
724+ {
725+ throw new Exception ( "get_value_3(int x)" ) ;
726+ }
727+
728+ public int GetValue ( int x )
729+ {
730+ throw new Exception ( "GetValue(int x)" ) ;
731+ }
732+
733+ public virtual int GetValue ( int x , int y )
734+ {
735+ throw new Exception ( "GetValue(int x, int y)" ) ;
736+ }
737+
738+ public virtual int GetValue2 ( int x )
739+ {
740+ throw new Exception ( "GetValue2(int x)" ) ;
741+ }
742+
743+ public int GetValue3 ( int x )
744+ {
745+ throw new Exception ( "GetValue3(int x)" ) ;
746+ }
747+ }
748+
749+ private class AlreadyDefinedSnakeCaseMemberTestDerivedClass : AlreadyDefinedSnakeCaseMemberTestBaseClass
750+ {
751+ public int SomeIntProperty { get ; set ; } = 111 ;
752+
753+ public override int AnotherIntProperty { get ; set ; } = 222 ;
754+
755+ public override int get_value ( int x )
756+ {
757+ throw new Exception ( "override get_value(int x)" ) ;
758+ }
759+
760+ public override int GetValue ( int x , int y )
761+ {
762+ throw new Exception ( "override GetValue(int x, int y)" ) ;
763+ }
764+
765+ public override int GetValue2 ( int x )
766+ {
767+ throw new Exception ( "override GetValue2(int x)" ) ;
768+ }
769+
770+ public new int GetValue3 ( int x )
771+ {
772+ throw new Exception ( "new GetValue3(int x)" ) ;
773+ }
774+ }
775+
776+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestBaseClass ) , "get_value" , new object [ ] { 2 , 3 } , "GetValue(int x, int y)" ) ]
777+ // 1 int arg, binds to the original c# class get_value(int x)
778+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestBaseClass ) , "get_value" , new object [ ] { 2 } , "get_value(int x)" ) ]
779+ // 2 int args, binds to the snake-cased overriden GetValue(int x, int y)
780+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestDerivedClass ) , "get_value" , new object [ ] { 2 , 3 } , "override GetValue(int x, int y)" ) ]
781+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestDerivedClass ) , "get_value" , new object [ ] { 2 } , "override get_value(int x)" ) ]
782+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestDerivedClass ) , "get_value_2" , new object [ ] { 2 } , "override GetValue2(int x)" ) ]
783+ [ TestCase ( typeof ( AlreadyDefinedSnakeCaseMemberTestDerivedClass ) , "get_value_3" , new object [ ] { 2 } , "new GetValue3(int x)" ) ]
784+ public void BindsSnakeCasedMethodAsOverload ( Type type , string methodName , object [ ] args , string expectedMessage )
785+ {
786+ var obj = Activator . CreateInstance ( type ) ;
787+ using var pyObj = obj . ToPython ( ) ;
788+
789+ using var method = pyObj . GetAttr ( methodName ) ;
790+ var pyArgs = args . Select ( x => x . ToPython ( ) ) . ToArray ( ) ;
791+
792+ var exception = Assert . Throws < Exception > ( ( ) => method . Invoke ( pyArgs ) ) ;
793+ Assert . AreEqual ( expectedMessage , exception . Message ) ;
794+
795+ foreach ( var x in pyArgs )
796+ {
797+ x . Dispose ( ) ;
798+ }
712799 }
713800
714801 [ Test ]
@@ -734,13 +821,6 @@ public void DoesntBindSnakeCasedMemberIfAlreadyOriginallyDefinedAsMethod()
734821 Assert . AreEqual ( 654 , method . Invoke ( ) . As < int > ( ) ) ;
735822 }
736823
737- private class AlreadyDefinedSnakeCaseMemberTestDerivedClass : AlreadyDefinedSnakeCaseMemberTestBaseClass
738- {
739- public int SomeIntProperty { get ; set ; } = 111 ;
740-
741- public int AnotherIntProperty { get ; set ; } = 222 ;
742- }
743-
744824 [ Test ]
745825 public void DoesntBindSnakeCasedMemberIfAlreadyOriginallyDefinedAsPropertyInBaseClass ( )
746826 {
0 commit comments