From: jpbruyere Date: Thu, 10 Sep 2015 23:12:04 +0000 (+0200) Subject: Hack hostClass to have it point to main window when custom class is X-Git-Tag: 0.2~43 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=53457ed25ba3f8d7535ddc9f2c0c7d3c04b8fdce;p=jp%2Fcrow.git Hack hostClass to have it point to main window when custom class is passed as data source --- diff --git a/src/Interface.cs b/src/Interface.cs index 69e8d9d0..9b6e3dc8 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -175,14 +175,21 @@ namespace go MethodInfo mi = hostClass.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + object effectiveHostClass = hostClass; if (mi == null) { - Debug.WriteLine ("Handler Method not found: " + es.Value); - continue; + //TODO: hack to have it work, hostClass and dataSource should be clearly separated + mi = OpenTKGameWindow.currentWindow.GetType ().GetMethod (es.Value, BindingFlags.NonPublic | BindingFlags.Public + | BindingFlags.Instance); + if (mi == null) { + Debug.WriteLine ("Handler Method not found: " + es.Value); + continue; + } + effectiveHostClass = OpenTKGameWindow.currentWindow; } EventInfo ei = es.Source.GetType ().GetEvent (es.MemberName); MethodInfo addHandler = ei.GetAddMethod (); - Delegate del = Delegate.CreateDelegate (ei.EventHandlerType, hostClass, mi); + Delegate del = Delegate.CreateDelegate (ei.EventHandlerType, effectiveHostClass, mi); addHandler.Invoke(es.Source, new object[] {del});