diff --git a/ChangeLog b/ChangeLog index 07ad529da..12c985152 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-12 Mike Kestner + + * glib/GType.cs: add ResolveType event and TypeResolutionHandler delegate + declarations. This mechanism supports the lazy registration of type mappings + by bindings. Patch from Sebastian with minor naming tweek. [Fixes #497667] + 2009-07-12 Mike Kestner * generator/Parameters.cs: another owned parameter patch from Sebastian. diff --git a/glib/GType.cs b/glib/GType.cs index 762b00639..c3f09404a 100755 --- a/glib/GType.cs +++ b/glib/GType.cs @@ -29,6 +29,8 @@ namespace GLib { using System.Runtime.InteropServices; using System.Text; + public delegate System.Type TypeResolutionHandler (GLib.GType gtype, string gtype_name); + [StructLayout(LayoutKind.Sequential)] public struct GType { @@ -175,12 +177,29 @@ namespace GLib { // cctor already calls g_type_init. } + public static event TypeResolutionHandler ResolveType; + public static Type LookupType (IntPtr typeid) { if (types.Contains (typeid)) return (Type)types[typeid]; string native_name = Marshaller.Utf8PtrToString (g_type_name (typeid)); + + if (ResolveType != null) { + GLib.GType gt = new GLib.GType (typeid); + + Delegate[] invocation_list = ResolveType.GetInvocationList (); + foreach (Delegate d in invocation_list) { + TypeResolutionHandler handler = (TypeResolutionHandler) d; + System.Type tmp = handler (gt, native_name); + if (tmp != null) { + Register (gt, tmp); + return tmp; + } + } + } + string type_name = GetQualifiedName (native_name); if (type_name == null) return null;