Skip to content

Commit b4cc35d

Browse files
committed
Merge branch 'csharp-strenghten-overload-check'
* csharp-strenghten-overload-check: Fix expanded director_basic test. Improve correctness of SwigDerivedClassHasMethod() by making sure only methods that have `override` are used connected by director.
2 parents 1ad77e8 + 15f9403 commit b4cc35d

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Source/Modules/csharp.cxx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,32 @@ class CSHARP:public Language {
19641964
// Only emit if there is at least one director method
19651965
Printf(proxy_class_code, "\n");
19661966
Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, global::System.Type[] methodTypes) {\n");
1967-
Printf(proxy_class_code,
1968-
" global::System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n");
1969-
Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name);
1967+
Printf(proxy_class_code, " global::System.Reflection.MethodInfo[] methodInfos = this.GetType().GetMethods(\n");
1968+
Printf(proxy_class_code, " global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance);\n");
1969+
Printf(proxy_class_code, " foreach (global::System.Reflection.MethodInfo methodInfo in methodInfos) {\n");
1970+
Printf(proxy_class_code, " if (methodInfo.DeclaringType == null)\n");
1971+
Printf(proxy_class_code, " continue;\n\n");
1972+
Printf(proxy_class_code, " if (methodInfo.Name != methodName)\n");
1973+
Printf(proxy_class_code, " continue;\n\n");
1974+
Printf(proxy_class_code, " var parameters = methodInfo.GetParameters();\n");
1975+
Printf(proxy_class_code, " if (parameters.Length != methodTypes.Length)\n");
1976+
Printf(proxy_class_code, " continue;\n\n");
1977+
Printf(proxy_class_code, " bool parametersMatch = true;\n");
1978+
Printf(proxy_class_code, " for (var i = 0; i < parameters.Length; i++) {\n");
1979+
Printf(proxy_class_code, " if (parameters[i].ParameterType != methodTypes[i]) {\n");
1980+
Printf(proxy_class_code, " parametersMatch = false;\n");
1981+
Printf(proxy_class_code, " break;\n");
1982+
Printf(proxy_class_code, " }\n");
1983+
Printf(proxy_class_code, " }\n\n");
1984+
Printf(proxy_class_code, " if (!parametersMatch)\n");
1985+
Printf(proxy_class_code, " continue;\n\n");
1986+
Printf(proxy_class_code, " if (methodInfo.IsVirtual && (methodInfo.DeclaringType.IsSubclassOf(typeof(%s))) &&\n", proxy_class_name);
1987+
Printf(proxy_class_code, " methodInfo.DeclaringType != methodInfo.GetBaseDefinition().DeclaringType) {\n");
1988+
Printf(proxy_class_code, " return true;\n");
1989+
Printf(proxy_class_code, " }\n");
1990+
Printf(proxy_class_code, " }\n\n");
1991+
Printf(proxy_class_code, " return false;\n");
1992+
19701993
/* Could add this code to cover corner case where the GetMethod() returns a method which allows type
19711994
* promotion, eg it will return foo(double), if looking for foo(int).
19721995
if (hasDerivedMethod) {
@@ -1986,7 +2009,7 @@ class CSHARP:public Language {
19862009
}
19872010
}
19882011
*/
1989-
Printf(proxy_class_code, " return hasDerivedMethod;\n");
2012+
//Printf(proxy_class_code, " return hasDerivedMethod;\n");
19902013
Printf(proxy_class_code, " }\n");
19912014
}
19922015

0 commit comments

Comments
 (0)