Only generate C# SwigDerivedClassHasMethod() if there are director methods in the class

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9140 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-06-02 21:00:26 +00:00
commit 1db0b8a0c0

View file

@ -1585,32 +1585,37 @@ class CSHARP : public Language {
Printf(proxy_class_code, ", swigDelegate%s", methid);
}
Printf(proxy_class_code, ");\n");
Printf(proxy_class_code, " }\n\n");
Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {\n");
Printf(proxy_class_code, " System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, methodTypes);\n");
Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name);
/* Could add this code to cover corner case where the GetMethod() returns a method which allows type
* promotion, eg it will return foo(double), if looking for foo(int).
if (hasDerivedMethod) {
hasDerivedMethod = false;
if (methodInfo != null)
{
hasDerivedMethod = true;
ParameterInfo[] parameterArray1 = methodInfo.GetParameters();
for (int i=0; i<methodTypes.Length; i++)
{
if (parameterArray1[0].ParameterType != methodTypes[0])
{
hasDerivedMethod = false;
break;
}
}
}
}
*/
Printf(proxy_class_code, " return hasDerivedMethod;\n");
Printf(proxy_class_code, " }\n");
if (first_class_dmethod < curr_class_dmethod) {
// Only emit if there is at least one director method
Printf(proxy_class_code, "\n");
Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {\n");
Printf(proxy_class_code, " System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, methodTypes);\n");
Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name);
/* Could add this code to cover corner case where the GetMethod() returns a method which allows type
* promotion, eg it will return foo(double), if looking for foo(int).
if (hasDerivedMethod) {
hasDerivedMethod = false;
if (methodInfo != null)
{
hasDerivedMethod = true;
ParameterInfo[] parameterArray1 = methodInfo.GetParameters();
for (int i=0; i<methodTypes.Length; i++)
{
if (parameterArray1[0].ParameterType != methodTypes[0])
{
hasDerivedMethod = false;
break;
}
}
}
}
*/
Printf(proxy_class_code, " return hasDerivedMethod;\n");
Printf(proxy_class_code, " }\n");
}
if (Len(director_delegate_callback) > 0)
Printv(proxy_class_code, director_delegate_callback, NIL);
if (Len(director_delegate_definitions) > 0)