[Gtk-sharp-list] Subclassing GLib.Object

Peter Williams peter@newton.cx
Sun, 16 May 2004 02:45:30 -0400


--=-ORKCTXYwLLNcoYghelx3
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

Maybe I'm not doing this correctly, but right now I think gtk# doesn't
let you create a subclass of GLib.Object directly, because
Object.LookupGType() gets GType.Invalid from the default GType property
of GLib.Object. The attached patch adds a special case to let you
subclass successfully.

Just in case I'm missing something, here's my use case:

        public class NautilusExtension : GLib.Object,
		Nautilus.ColumnProvider,
		Nautilus.InfoProvider {

		static GLib.GType type;

		static NautilusExtension() {
			type = GLib.Object.RegisterGType (typeof (NautilusExtension));
		}

		public NautilusExtension() : base (type) {
		}
	}

Peter

-- 
Peter Williams                          peter@newton.cx

"[Ninjas] are cool; and by cool, I mean totally sweet."
                              -- REAL Ultimate Power

--=-ORKCTXYwLLNcoYghelx3
Content-Description: 
Content-Disposition: inline; filename=obj-subclass.diff
Content-Type: text/x-patch; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

Index: ChangeLog
===================================================================
RCS file: /cvs/public/gtk-sharp/ChangeLog,v
retrieving revision 1.805
diff -u -r1.805 ChangeLog
--- ChangeLog	14 May 2004 20:25:56 -0000	1.805
+++ ChangeLog	16 May 2004 05:55:00 -0000
@@ -1,3 +1,8 @@
+2004-05-16  Peter Williams  <peter@newton.cx>
+
+	* glib/Object.cs: Special-case t == typeof (Object). This allows
+	people to subclass directly from GLib.Object.
+
 2004-05-14  Todd Berman  <tberman@sevenl.net>
 
 	* glib/Object.cs: make static GLib.Object.LookupGType protected for now.
Index: glib/Object.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/glib/Object.cs,v
retrieving revision 1.62
diff -u -r1.62 Object.cs
--- glib/Object.cs	14 May 2004 20:25:56 -0000	1.62
+++ glib/Object.cs	16 May 2004 05:55:00 -0000
@@ -148,7 +148,10 @@
 		{
 			if (g_types.Contains (t))
 				return (GType) g_types [t];
-			
+
+			if (t == typeof (Object))
+				return GType.Object;
+
 			PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public);
 			if (pi != null)
 				return (GType) pi.GetValue (null, null);

--=-ORKCTXYwLLNcoYghelx3--