Skip to content

Commit 15f9403

Browse files
committed
Fix expanded director_basic test.
Since we are mixing `new` and `override` a class instance may have multiple methods with the same name. in case of director_basic test one method comes from `MyClassMiddle` (one that participates in dynamic dispatch) and one comes from `MyClassEnd` (one with `new` keyword). Therefore all methods have to be checked.
1 parent 82a6fe0 commit 15f9403

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
@@ -1951,9 +1951,32 @@ class CSHARP:public Language {
19511951
// Only emit if there is at least one director method
19521952
Printf(proxy_class_code, "\n");
19531953
Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, global::System.Type[] methodTypes) {\n");
1954-
Printf(proxy_class_code,
1955-
" 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");
1956-
Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.IsVirtual && methodInfo.DeclaringType.IsSubclassOf(typeof(%s)) && methodInfo.DeclaringType != methodInfo.GetBaseDefinition().DeclaringType;\n", proxy_class_name);
1954+
Printf(proxy_class_code, " global::System.Reflection.MethodInfo[] methodInfos = this.GetType().GetMethods(\n");
1955+
Printf(proxy_class_code, " global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance);\n");
1956+
Printf(proxy_class_code, " foreach (global::System.Reflection.MethodInfo methodInfo in methodInfos) {\n");
1957+
Printf(proxy_class_code, " if (methodInfo.DeclaringType == null)\n");
1958+
Printf(proxy_class_code, " continue;\n\n");
1959+
Printf(proxy_class_code, " if (methodInfo.Name != methodName)\n");
1960+
Printf(proxy_class_code, " continue;\n\n");
1961+
Printf(proxy_class_code, " var parameters = methodInfo.GetParameters();\n");
1962+
Printf(proxy_class_code, " if (parameters.Length != methodTypes.Length)\n");
1963+
Printf(proxy_class_code, " continue;\n\n");
1964+
Printf(proxy_class_code, " bool parametersMatch = true;\n");
1965+
Printf(proxy_class_code, " for (var i = 0; i < parameters.Length; i++) {\n");
1966+
Printf(proxy_class_code, " if (parameters[i].ParameterType != methodTypes[i]) {\n");
1967+
Printf(proxy_class_code, " parametersMatch = false;\n");
1968+
Printf(proxy_class_code, " break;\n");
1969+
Printf(proxy_class_code, " }\n");
1970+
Printf(proxy_class_code, " }\n\n");
1971+
Printf(proxy_class_code, " if (!parametersMatch)\n");
1972+
Printf(proxy_class_code, " continue;\n\n");
1973+
Printf(proxy_class_code, " if (methodInfo.IsVirtual && (methodInfo.DeclaringType.IsSubclassOf(typeof(%s))) &&\n", proxy_class_name);
1974+
Printf(proxy_class_code, " methodInfo.DeclaringType != methodInfo.GetBaseDefinition().DeclaringType) {\n");
1975+
Printf(proxy_class_code, " return true;\n");
1976+
Printf(proxy_class_code, " }\n");
1977+
Printf(proxy_class_code, " }\n\n");
1978+
Printf(proxy_class_code, " return false;\n");
1979+
19571980
/* Could add this code to cover corner case where the GetMethod() returns a method which allows type
19581981
* promotion, eg it will return foo(double), if looking for foo(int).
19591982
if (hasDerivedMethod) {
@@ -1973,7 +1996,7 @@ class CSHARP:public Language {
19731996
}
19741997
}
19751998
*/
1976-
Printf(proxy_class_code, " return hasDerivedMethod;\n");
1999+
//Printf(proxy_class_code, " return hasDerivedMethod;\n");
19772000
Printf(proxy_class_code, " }\n");
19782001
}
19792002

0 commit comments

Comments
 (0)