From b15f2eede1ec7db63eb60589851e1560cef3d98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20G=2E=20Aragoneses?= Date: Sat, 12 Oct 2013 14:09:23 +0200 Subject: [PATCH] generator: provide a GType static property for adapters In the same way all GLib.Object-derived classes provided by the generator have a GType static property (i.e. Gtk.Widget), we need the same for the *Adapter classes, to access their GType without having an instance of it. (The first use case would be GStreamerSharp's Gst.Bin.IterateAllByInterface ().) For this, we cannot simply add the property to all adapter classes and be done, because it would clash with a property which is already there, but is non-static, that has the same name and same value (this property is needed for complying GInterfaceAdapter abstract class), so we rename this property to GInterfaceGType because using this name for the static one would not be consistent with the rest of the classes generated which already provide the static one with the name "GType". --- generator/InterfaceGen.cs | 13 ++++++++++++- glib/GInterfaceAdapter.cs | 2 +- glib/Object.cs | 4 ++-- glib/Value.cs | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 6d1185223..c6cecdf16 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -197,12 +197,23 @@ namespace GtkSharp.Generation { m.GenerateImport (sw); sw.WriteLine ("\t\tprivate static GLib.GType _gtype = new GLib.GType ({0} ());", m.CName); sw.WriteLine (); - sw.WriteLine ("\t\tpublic override GLib.GType GType {"); + + // by convention, all GTypes generated have a static GType property + sw.WriteLine ("\t\tpublic static GLib.GType GType {"); sw.WriteLine ("\t\t\tget {"); sw.WriteLine ("\t\t\t\treturn _gtype;"); sw.WriteLine ("\t\t\t}"); sw.WriteLine ("\t\t}"); sw.WriteLine (); + + // we need same property but non-static, because it is being accessed via a GInterfaceAdapter instance + sw.WriteLine ("\t\tpublic override GLib.GType GInterfaceGType {"); + sw.WriteLine ("\t\t\tget {"); + sw.WriteLine ("\t\t\t\treturn _gtype;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t}"); + + sw.WriteLine (); } void GenerateHandleProp (StreamWriter sw) diff --git a/glib/GInterfaceAdapter.cs b/glib/GInterfaceAdapter.cs index ab71f6829..f86636711 100644 --- a/glib/GInterfaceAdapter.cs +++ b/glib/GInterfaceAdapter.cs @@ -50,7 +50,7 @@ namespace GLib { } } - public abstract GType GType { get; } + public abstract GType GInterfaceGType { get; } public abstract IntPtr Handle { get; } diff --git a/glib/Object.cs b/glib/Object.cs index c1ed9642c..74994813e 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -225,7 +225,7 @@ namespace GLib { if (!iface.IsAssignableFrom (Type.BaseType)) { GInterfaceInfo info = adapter.Info; info.Data = gtype.Val; - g_type_add_interface_static (gtype.Val, adapter.GType.Val, ref info); + g_type_add_interface_static (gtype.Val, adapter.GInterfaceGType.Val, ref info); adapters.Add (adapter); } } @@ -341,7 +341,7 @@ namespace GLib { PropertyInfo declared_prop = Type.GetProperty (p.Name, BindingFlags.Public | BindingFlags.Instance); if (declared_prop == null) continue; - IntPtr param_spec = FindInterfaceProperty (adapter.GType, property_attr.Name); + IntPtr param_spec = FindInterfaceProperty (adapter.GInterfaceGType, property_attr.Name); Dictionary props; if (!Properties.TryGetValue (Type, out props)) { diff --git a/glib/Value.cs b/glib/Value.cs index 1c89cc37d..9b8b93745 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -134,7 +134,7 @@ namespace GLib { g_value_set_object (ref this, val == null ? IntPtr.Zero : val.Handle); } - public Value (GLib.GInterfaceAdapter val) : this (val == null ? GType.Object : val.GType) + public Value (GLib.GInterfaceAdapter val) : this (val == null ? GType.Object : val.GInterfaceGType) { g_value_set_object (ref this, val == null ? IntPtr.Zero : val.Handle); }