mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-08 07:53:17 +02:00
2006-06-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* glade/HandlerNotFoundExeception.cs: * glade/XML.custom: provide a better error when the signature of a handler does not match the one of the event. svn path=/trunk/gtk-sharp/; revision=61911
This commit is contained in:
parent
7d9ac6ec4b
commit
1843575303
@ -1,3 +1,9 @@
|
|||||||
|
2006-06-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>
|
||||||
|
|
||||||
|
* 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 <mkestner@novell.com>
|
2006-05-10 Mike Kestner <mkestner@novell.com>
|
||||||
|
|
||||||
* bootstrap-2.10 : strap for the new 2.9.0 API.
|
* bootstrap-2.10 : strap for the new 2.9.0 API.
|
||||||
|
@ -52,6 +52,17 @@ namespace Glade {
|
|||||||
this.delegate_type = delegate_type;
|
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)
|
protected HandlerNotFoundException (SerializationInfo info, StreamingContext context)
|
||||||
: base (info, context)
|
: base (info, context)
|
||||||
{
|
{
|
||||||
|
@ -257,12 +257,69 @@
|
|||||||
|
|
||||||
if (!connected)
|
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);
|
System.Reflection.MemberFilter signalFilter = new System.Reflection.MemberFilter (SignalFilter);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user