public void GetMethodDescriptionAndObject(Type type, IntPtr selector, bool is_static, IntPtr obj, ref IntPtr mthis, IntPtr desc) { var sel = Selector.GetName(selector); var res = GetMethodNoThrow(type, type, sel, is_static); if (res == null) { throw ErrorHelper.CreateError(8006, "Failed to find the selector '{0}' on the type '{1}'", sel, type.FullName); } if (res.IsInstanceCategory) { mthis = IntPtr.Zero; } else { try { var nsobj = Runtime.GetNSObject(obj, Runtime.MissingCtorResolution.ThrowConstructor1NotFound, true); mthis = Runtime.AllocGCHandle(nsobj); if (res.Method.ContainsGenericParameters) { res.WriteUnmanagedDescription(desc, Runtime.FindClosedMethod(nsobj.GetType(), res.Method)); return; } } catch (Exception e) { throw ErrorHelper.CreateError(8035, e, $"Failed to get the 'this' instance in a method call to {res.DescriptiveMethodName}."); } } res.WriteUnmanagedDescription(desc); }
internal static IntPtr CreateNSObject(IntPtr type_gchandle, IntPtr handle, Flags flags) { // This function is called from native code before any constructors have executed. var type = (Type)Runtime.GetGCHandleTarget(type_gchandle); var obj = (NSObject)RuntimeHelpers.GetUninitializedObject(type); obj.handle = handle; obj.flags = flags; return(Runtime.AllocGCHandle(obj)); }
internal static IntPtr CreateNSObject(IntPtr type_gchandle, IntPtr handle, Flags flags) { // This function is called from native code before any constructors have executed. var type = (Type)Runtime.GetGCHandleTarget(type_gchandle); try { var obj = (NSObject)RuntimeHelpers.GetUninitializedObject(type); obj.handle = handle; obj.flags = flags; return(Runtime.AllocGCHandle(obj)); } catch (Exception e) { throw ErrorHelper.CreateError(8041, e, Errors.MX8041 /* Unable to create an instance of the type {0} */, type.FullName); } }