[Mono-dev] Embedding + GObject Subclasses

Christian Hoff christian_hoff at gmx.net
Thu Sep 3 14:25:46 EDT 2009


Matthew Metnetsky wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> All,
>
> Suppose I had the following class:
>
> class Foo : Gtk.Box
> {
>   public new int Spacing {
>     Console.WriteLine("HI");
>     return base.Spacing;
>   }
> }
>
> which is compiled into Foo.dll. Is there a way from within a native
> application to instantiate Foo via it's GType like:
>
> GObject * o = g_object_new(FooType, NULL);
>   
I'm not 100% sure if that works; just give it a try. FooType can only be 
obtained by calling managed code (FooType = (Glib.GType) Foo).
> So in other words, I have mono embedded and was wondering if there is a
> way to make use of sub-classing GObject succinctly execute MonoMethod's.
>   
Don't expect the managed Spacing property to be called. We don't support 
overridding GObject proprties, which is why they are non-virtual. But 
since Gtk# 2.12.2 you can register your own managed properties within 
the GObject type system.

Just use
[GLib.Property ("testprop")}
public int Testprop { .... }

and you should be able to access the property from native code.


Christian



More information about the Mono-devel-list mailing list