Author: gonzalo
Date: 2006-06-21 11:57:26 -0400 (Wed, 21 Jun 2006)
New Revision: 61911
Modified:
trunk/gtk-sharp/ChangeLog
trunk/gtk-sharp/glade/HandlerNotFoundExeception.cs
trunk/gtk-sharp/glade/XML.custom
Log:
2006-06-21 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* glade/HandlerNotFoundExeception.cs:
* glade/XML.custom: provide a better error when the signature of a
handler does not match the one of the event.
Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog 2006-06-21 15:57:20 UTC (rev 61910)
+++ trunk/gtk-sharp/ChangeLog 2006-06-21 15:57:26 UTC (rev 61911)
@@ -1,3 +1,9 @@
+2006-06-21 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * glade/HandlerNotFoundExeception.cs:
+ * glade/XML.custom: provide a better error when the signature of a
+ handler does not match the one of the event.
+
2006-05-10 Mike Kestner <[EMAIL PROTECTED]>
* bootstrap-2.10 : strap for the new 2.9.0 API.
Modified: trunk/gtk-sharp/glade/HandlerNotFoundExeception.cs
===================================================================
--- trunk/gtk-sharp/glade/HandlerNotFoundExeception.cs 2006-06-21 15:57:20 UTC
(rev 61910)
+++ trunk/gtk-sharp/glade/HandlerNotFoundExeception.cs 2006-06-21 15:57:26 UTC
(rev 61911)
@@ -52,6 +52,17 @@
this.delegate_type = delegate_type;
}
+ public HandlerNotFoundException (string message, string
handler_name, string signal_name,
+ EventInfo evnt, Type
delegate_type)
+ : base ((message != null) ? message : "No handler " +
handler_name + " found for signal " + signal_name,
+ null)
+ {
+ this.handler_name = handler_name;
+ this.signal_name = signal_name;
+ this.evnt = evnt;
+ this.delegate_type = delegate_type;
+ }
+
protected HandlerNotFoundException (SerializationInfo info,
StreamingContext context)
: base (info, context)
{
Modified: trunk/gtk-sharp/glade/XML.custom
===================================================================
--- trunk/gtk-sharp/glade/XML.custom 2006-06-21 15:57:20 UTC (rev 61910)
+++ trunk/gtk-sharp/glade/XML.custom 2006-06-21 15:57:26 UTC (rev 61911)
@@ -257,12 +257,69 @@
if (!connected)
{
- throw new
HandlerNotFoundException (handler_name, signal_name, ei, delegate_type);
+ string msg =
ExplainError (ei.Name, delegate_type, handler_type, handler_name);
+ throw new
HandlerNotFoundException (msg, handler_name, signal_name, ei, delegate_type);
}
}
}
}
+
+ static string GetSignature
(System.Reflection.MethodInfo method)
+ {
+ if (method == null)
+ return null;
+
+ System.Reflection.ParameterInfo [] parameters =
method.GetParameters ();
+ System.Text.StringBuilder sb = new
System.Text.StringBuilder ();
+ sb.Append ('(');
+ foreach (System.Reflection.ParameterInfo info
in parameters) {
+ sb.Append (info.ParameterType.ToString
());
+ sb.Append (',');
+ }
+ if (sb.Length != 0)
+ sb.Length--;
+
+ sb.Append (')');
+ return sb.ToString ();
+ }
+
+ static string GetSignature (Type delegate_type)
+ {
+ System.Reflection.MethodInfo method =
delegate_type.GetMethod ("Invoke");
+ return GetSignature (method);
+ }
+
+ const System.Reflection.BindingFlags flags =
System.Reflection.BindingFlags.NonPublic |
+
System.Reflection.BindingFlags.Public |
+
System.Reflection.BindingFlags.Static |
+
System.Reflection.BindingFlags.Instance;
+ static string GetSignature (Type klass, string
method_name)
+ {
+ try {
+ System.Reflection.MethodInfo method =
klass.GetMethod (method_name, flags);
+ return GetSignature (method);
+ } catch {
+ // May be more than one method with
that name and none matches
+ return null;
+ }
+ }
+
+ static string ExplainError (string event_name, Type
deleg, Type klass, string method)
+ {
+ if (deleg == null || klass == null || method ==
null)
+ return null;
+
+ System.Text.StringBuilder sb = new
System.Text.StringBuilder ();
+ string expected = GetSignature (deleg);
+ string actual = GetSignature (klass, method);
+ if (actual == null)
+ return null;
+ sb.AppendFormat ("The handler for the
event {0} should take '{1}', " +
+ "but the signature of the
provided handler ('{2}') is '{3}'\n",
+ event_name, expected, method,
actual);
+ return sb.ToString ();
+ }
System.Reflection.MemberFilter signalFilter = new
System.Reflection.MemberFilter (SignalFilter);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches