Chris Szikszoy wrote:
I saw that GIO# bindings landed in the mainline gtk# branch recently and
wanted experiment to see if I could replace the old Gnome.VFS in my
application.  I've built the latest gtk# from svn and am running into a
problem with the VolumeMonitor.Mount* signals.  I keep getting an
InvalidCastException when trying to access args.Mount from any of the events
(MountAdded, MountRemoved, MountPreUnmount, MountChanged).

I've looked at the generated code and it seems to be failing at here:
public Mount Mount{
        get {
                return (GLib.Mount)GLib.SignalArgs.get_Args()[0];
        }
}

I have attached a patch which fixes the issue together with a modified version of your test program. Mike, could you review?


Christian

Index: generator/Signal.cs
===================================================================
--- generator/Signal.cs	(Revision 143910)
+++ generator/Signal.cs	(Arbeitskopie)
@@ -271,12 +271,18 @@
 				sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
 				if (parms[i].PassAs != "out") {
 					sw.WriteLine ("\t\t\tget {");
-					sw.WriteLine ("\t\t\t\treturn (" + parms[i].CSType + ") Args[" + i + "];");
+					if (SymbolTable.Table.IsInterface (parms [i].CType))
+						sw.WriteLine ("\t\t\t\treturn {0}Adapter.GetObject (Args [{1}] as GLib.Object);", parms [i].CSType, i);
+					else
+						sw.WriteLine ("\t\t\t\treturn ({0}) Args [{1}];", parms [i].CSType, i);
 					sw.WriteLine ("\t\t\t}");
 				}
 				if (parms[i].PassAs != "") {
 					sw.WriteLine ("\t\t\tset {");
-					sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
+					if (SymbolTable.Table.IsInterface (parms [i].CType))
+						sw.WriteLine ("\t\t\t\tArgs [{0}] = value is {1}Adapter ? (value as {1}Adapter).Implementor : value;", i, parms [i].CSType);
+					else
+						sw.WriteLine ("\t\t\t\tArgs[" + i + "] = (" + parms[i].CSType + ")value;");
 					sw.WriteLine ("\t\t\t}");
 				}
 				sw.WriteLine ("\t\t}");
using System;
using GLib;

namespace giotest
{
	static class MainClass
	{
		static GLib.MainLoop loop;

		public static void Main (string[] args)
		{
			GLib.GType.Init ();

			VolumeMonitor mon = VolumeMonitor.Default;

			mon.MountAdded += delegate(object o, MountAddedArgs a) {
				Console.WriteLine ("Mount Added: {0}", a.Mount.Name);
				loop.Quit ();
			};
			mon.MountRemoved += delegate(object o, MountRemovedArgs a) {
				Console.WriteLine ("Mount removed: {0}", a.Mount.Name);
				loop.Quit ();
			};

			loop = new GLib.MainLoop ();
			loop.Run ();
		}
	}
}
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to