| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c69fb42 commit c799b7e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -805,6 +805,34 @@ public string ImplicitConversionSameArgumentCount2(string symbol, decimal quanti | |||
| 805 | 805 | { | |
| 806 | 806 | return "ImplicitConversionSameArgumentCount2 2"; | |
| 807 | 807 | } | |
| 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 | + } | ||
| 808 | 836 | } | |
| 809 | 837 | ||
| 810 | 838 | [TestCase("Method1('abc', namedArg1=10, namedArg2=321)", "Method1 Overload 1")] | |
@@ -907,7 +935,7 @@ public void BindsConstructorToSnakeCasedArgumentsVersion([Values] bool useCamelC | |||
| 907 | 935 | var argument2Name = useCamelCase ? "anotherArgument" : "another_argument"; | |
| 908 | 936 | var argument2Code = passOptionalArgument ? $", {argument2Name}=\"another argument value\"" : ""; | |
| 909 | 937 | ||
| 910 | - var module = PyModule.FromString("CallsCorrectOverloadWithoutErrors", @$" | ||
| 938 | + var module = PyModule.FromString("BindsConstructorToSnakeCasedArgumentsVersion", @$" | ||
| 911 | 939 | from clr import AddReference | |
| 912 | 940 | AddReference(""System"") | |
| 913 | 941 | from Python.EmbeddingTest import * | |
@@ -925,6 +953,49 @@ def create_instance(): | |||
| 925 | 953 | Assert.AreEqual(expectedMessage, sourceException.Message); | |
| 926 | 954 | } | |
| 927 | 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 | + | ||
| 998 | + | ||
| 928 | 999 | // Used to test that we match this function with Py DateTime & Date Objects | |
| 929 | 1000 | public static int GetMonth(DateTime test) | |
| 930 | 1001 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -553,7 +553,7 @@ void AddMember(string name, string snakeCasedName, bool isStaticReadonlyCallable | |||
| 553 | 553 | } | |
| 554 | 554 | methodList.Add(ctor, true); | |
| 555 | 555 | // Same constructor, but with snake-cased arguments | |
| 556 | - if (ctor.GetParameters().Any(pi => pi.Name.ToSnakeCase() != pi.Name)) | ||
| 556 | + if (ctor.GetParameters().Any(pi => pi.Name?.ToSnakeCase() != pi.Name)) | ||
| 557 | 557 | { | |
| 558 | 558 | methodList.Add(ctor, false); | |
| 559 | 559 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -365,6 +365,16 @@ internal static int ArgPrecedence(Type t, MethodInformation mi) | |||
| 365 | 365 | return -1; | |
| 366 | 366 | } | |
| 367 | 367 | ||
| 368 | + if (t.IsArray) | ||
| 369 | + { | ||
| 370 | + Type e = t.GetElementType(); | ||
| 371 | + if (e == objectType) | ||
| 372 | + { | ||
| 373 | + return 2500; | ||
| 374 | + } | ||
| 375 | + return 100 + ArgPrecedence(e, mi); | ||
| 376 | + } | ||
| 377 | + | ||
| 368 | 378 | TypeCode tc = Type.GetTypeCode(t); | |
| 369 | 379 | // TODO: Clean up | |
| 370 | 380 | switch (tc) | |
@@ -406,16 +416,6 @@ internal static int ArgPrecedence(Type t, MethodInformation mi) | |||
| 406 | 416 | return 40; | |
| 407 | 417 | } | |
| 408 | 418 | ||
| 409 | - if (t.IsArray) | ||
| 410 | - { | ||
| 411 | - Type e = t.GetElementType(); | ||
| 412 | - if (e == objectType) | ||
| 413 | - { | ||
| 414 | - return 2500; | ||
| 415 | - } | ||
| 416 | - return 100 + ArgPrecedence(e, mi); | ||
| 417 | - } | ||
| 418 | - | ||
| 419 | 419 | return 2000; | |
| 420 | 420 | } | |
| 421 | 421 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments