From d686a4d6aae0245fdebcfaa454c8af042c4c0475 Mon Sep 17 00:00:00 2001 From: Michael Hutchinson Date: Wed, 19 Sep 2012 19:41:04 -0400 Subject: [PATCH] Added Object.TryGetObject that gets wrapper only if already surfaced --- glib/Object.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/glib/Object.cs b/glib/Object.cs index 64c579092..721c6604f 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -82,6 +82,19 @@ namespace GLib { [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_object_unref (IntPtr raw); + public static Object TryGetObject (IntPtr o) + { + if (o == IntPtr.Zero) + return null; + + ToggleRef tr = (ToggleRef) Objects[o]; + if (tr != null) { + return tr.Target; + } + + return null; + } + public static Object GetObject(IntPtr o, bool owned_ref) { if (o == IntPtr.Zero)