diff --git a/ChangeLog b/ChangeLog index 3b2c0dc0b..fd668f810 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-05-18 Mike Kestner + + * glib/MissingIntPtrCtorException.cs : new exception to throw if + unable to access an IntPtr ctor on a GLib.Object subclass. We need + an IntPtr ctor to be able to wrap arbitrary object handles. + * glib/Object.cs : have NativeType call LookupGType. + * glib/ObjectManager.cs : throw the new exception in a try/catch. + 2004-05-17 Mike Kestner * generator/ObjectGen.cs : Generate a .cctor that calls the assembly's diff --git a/glib/Makefile.am b/glib/Makefile.am index ebe969416..6d70fef7f 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -26,6 +26,7 @@ sources = \ ManagedValue.cs \ Markup.cs \ Marshaller.cs \ + MissingIntPtrCtorException.cs \ Object.cs \ ObjectManager.cs \ Opaque.cs \ diff --git a/glib/MissingIntPtrCtorException.cs b/glib/MissingIntPtrCtorException.cs new file mode 100644 index 000000000..1f6d15b10 --- /dev/null +++ b/glib/MissingIntPtrCtorException.cs @@ -0,0 +1,20 @@ +// MissingIntPtrCtorException.cs : Exception for missing IntPtr ctors +// +// Authors: Mike Kestner +// +// Copyright (c) 2004 Novell, Inc. + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + public class MissingIntPtrCtorException : Exception + { + public MissingIntPtrCtorException (string msg) : base (msg) + { + } + + } +} + diff --git a/glib/Object.cs b/glib/Object.cs index ede5150bc..c2142cfbb 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -207,10 +207,7 @@ namespace GLib { internal GLib.GType NativeType { get { - if (_obj == IntPtr.Zero) - return GType.Invalid; - - return new GLib.GType (gtksharp_get_type_id (_obj)); + return LookupGType (); } } diff --git a/glib/ObjectManager.cs b/glib/ObjectManager.cs index 22f8ac05c..76dd09d73 100644 --- a/glib/ObjectManager.cs +++ b/glib/ObjectManager.cs @@ -40,7 +40,13 @@ namespace GtkSharp { return null; } - return (GLib.Object) Activator.CreateInstance (t, new object[] {raw}); + GLib.Object obj; + try { + obj = (GLib.Object) Activator.CreateInstance (t, new object[] {raw}); + } catch (MissingMethodException) { + throw new GLib.MissingIntPtrCtorException ("All GLib.Object subclasses must provide a protected or public IntPtr ctor to support wrapping of native object handles."); + } + return obj; } public static void RegisterType (string native_name, string managed_name, string assembly)