Skip to content

Commit

Permalink
[Foundation] Document and slightly simplify the NSObject.Dangerous[Re…
Browse files Browse the repository at this point in the history
…tain|Release|Autorelease] methods. (#21844)
  • Loading branch information
rolfbjarne authored Dec 30, 2024
1 parent bc9d390 commit 619a8ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 18 additions & 10 deletions src/Foundation/NSObject2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,17 @@ bool DynamicConformsToProtocol (NativeHandle protocol)
return false;
}

/// <summary>Calls the 'release' selector on this object.</summary>
[EditorBrowsable (EditorBrowsableState.Advanced)]
public void DangerousRelease ()
{
DangerousRelease (handle);
}

/// <summary>Calls the 'release' selector on an Objective-C object.</summary>
/// <param name="handle">The Objective-C object to release.</param>
/// <remarks>It's safe to call this function with <see cref="NativeHandle.Zero" />.</remarks>
[EditorBrowsable (EditorBrowsableState.Never)]
internal static void DangerousRelease (NativeHandle handle)
{
if (handle == IntPtr.Zero)
Expand All @@ -586,6 +591,10 @@ internal static void DangerousRelease (NativeHandle handle)
#endif
}

/// <summary>Calls the 'retain' selector on an Objective-C object.</summary>
/// <param name="handle">The Objective-C object to retain.</param>
/// <remarks>It's safe to call this function with <see cref="NativeHandle.Zero" />.</remarks>
[EditorBrowsable (EditorBrowsableState.Never)]
internal static void DangerousRetain (NativeHandle handle)
{
if (handle == IntPtr.Zero)
Expand All @@ -597,6 +606,9 @@ internal static void DangerousRetain (NativeHandle handle)
#endif
}

/// <summary>Calls the 'autorelease' selector on an Objective-C object.</summary>
/// <param name="handle">The Objective-C object to autorelease.</param>
/// <remarks>It's safe to call this function with <see cref="NativeHandle.Zero" />.</remarks>
internal static void DangerousAutorelease (NativeHandle handle)
{
#if MONOMAC
Expand All @@ -606,25 +618,21 @@ internal static void DangerousAutorelease (NativeHandle handle)
#endif
}

/// <summary>Calls the 'retain' selector on this object.</summary>
/// <returns>This object.</returns>
[EditorBrowsable (EditorBrowsableState.Advanced)]
public NSObject DangerousRetain ()
{
#if MONOMAC
Messaging.void_objc_msgSend (handle, Selector.RetainHandle);
#else
Messaging.void_objc_msgSend (handle, Selector.GetHandle (Selector.Retain));
#endif
DangerousRetain (handle);
return this;
}

/// <summary>Calls the 'autorelease' selector on this object.</summary>
/// <returns>This object.</returns>
[EditorBrowsable (EditorBrowsableState.Advanced)]
public NSObject DangerousAutorelease ()
{
#if MONOMAC
Messaging.void_objc_msgSend (handle, Selector.AutoreleaseHandle);
#else
Messaging.void_objc_msgSend (handle, Selector.GetHandle (Selector.Autorelease));
#endif
DangerousAutorelease (handle);
return this;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33718,9 +33718,6 @@ M:Foundation.NSObject.Bind(Foundation.NSString,Foundation.NSObject,System.String
M:Foundation.NSObject.CommitEditing
M:Foundation.NSObject.CommitEditing(Foundation.NSObject,ObjCRuntime.Selector,System.IntPtr)
M:Foundation.NSObject.ConformsToProtocol(ObjCRuntime.NativeHandle)
M:Foundation.NSObject.DangerousAutorelease
M:Foundation.NSObject.DangerousRelease
M:Foundation.NSObject.DangerousRetain
M:Foundation.NSObject.Dispose
M:Foundation.NSObject.Dispose(System.Boolean)
M:Foundation.NSObject.DoesNotRecognizeSelector(ObjCRuntime.Selector)
Expand Down

8 comments on commit 619a8ea

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.