diff --git a/Libs/GObject-2.0/Classes/ConstructAttribute.cs b/Libs/GObject-2.0/Classes/ConstructAttribute.cs new file mode 100644 index 000000000..d6dd65c56 --- /dev/null +++ b/Libs/GObject-2.0/Classes/ConstructAttribute.cs @@ -0,0 +1,16 @@ +using System; + +namespace GObject +{ + /// + /// This attribute can be used to give the runtime + /// an alternative constructor method. This is + /// usefull if a constructor should return a + /// more derived type than the constructor itself. + /// + [AttributeUsage(AttributeTargets.Method)] + public class ConstructAttribute : Attribute + { + + } +} diff --git a/Libs/GObject-2.0/Native/Classes/BoxedWrapper.cs b/Libs/GObject-2.0/Native/Classes/BoxedWrapper.cs index 942898d75..cc1ade124 100644 --- a/Libs/GObject-2.0/Native/Classes/BoxedWrapper.cs +++ b/Libs/GObject-2.0/Native/Classes/BoxedWrapper.cs @@ -1,8 +1,6 @@ using System; -using System.Diagnostics; +using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; -using GLib; namespace GObject.Native { @@ -44,13 +42,11 @@ public static object WrapHandle(IntPtr handle, Type gtype) private static MethodInfo? GetSecretFactoryMethod(System.Type type) { - // Create using 'IntPtr' constructor - MethodInfo? ctor = type.GetMethod("__FactoryNew", - System.Reflection.BindingFlags.NonPublic - | System.Reflection.BindingFlags.Static, - null, new[] { typeof(IntPtr) }, null - ); - return ctor; + return type.GetMethods( + System.Reflection.BindingFlags.Static + | System.Reflection.BindingFlags.DeclaredOnly + | System.Reflection.BindingFlags.NonPublic + ).FirstOrDefault(x => x.GetCustomAttribute() is { }); } private static ConstructorInfo? GetBoxedConstructor(System.Type type) diff --git a/Libs/Gdk-3.0/Records/Event.cs b/Libs/Gdk-3.0/Records/Event.cs index f9cfa8873..5099a9479 100644 --- a/Libs/Gdk-3.0/Records/Event.cs +++ b/Libs/Gdk-3.0/Records/Event.cs @@ -5,8 +5,9 @@ namespace Gdk { public partial class Event { - //TODO: This method is our "secret factory method". it gets called via reflection. - //See BoxedWrapper.cs + // TODO: Workaround as long as we need GDK3 or + // do not create instances from safe handles + [GObject.Construct] private static Event __FactoryNew(IntPtr ptr) { var ev = Marshal.PtrToStructure(ptr);