diff --git a/src/ObjCRuntime/BackingField.cs b/src/ObjCRuntime/BackingField.cs
index 3692df3c3dda..333f4b6efbcb 100644
--- a/src/ObjCRuntime/BackingField.cs
+++ b/src/ObjCRuntime/BackingField.cs
@@ -37,15 +37,23 @@
#if IOS
-// Disable until we get around to enable + fix any issues.
-#nullable disable
+#nullable enable
namespace ObjCRuntime {
+ /// Helpers to convert between native handles and cached managed wrappers.
static class BackingField {
- public static T Get (ref T value, IntPtr handle, Converter c)
+ /// Gets a cached managed wrapper or creates a new one from a native handle.
+ /// The managed wrapper type.
+ /// The cached managed value.
+ /// The native handle.
+ /// A converter that creates a managed wrapper from a native handle.
+ /// The cached or newly created managed value, or if is .
+ public static T? Get (ref T? value, IntPtr handle, Converter c)
where T : class, INativeObject, IDisposable
{
+ c = ThrowHelper.ThrowIfNull (c);
+
if (handle == IntPtr.Zero) {
if (value is not null)
value.Dispose ();
@@ -59,7 +67,12 @@ public static T Get (ref T value, IntPtr handle, Converter c)
return value = c (handle);
}
- public static IntPtr Save (ref T value, T newValue)
+ /// Saves a managed wrapper in a backing field and returns the corresponding native handle.
+ /// The managed wrapper type.
+ /// The current cached managed value.
+ /// The new managed value to cache.
+ /// The native handle for , or if is .
+ public static IntPtr Save (ref T? value, T? newValue)
where T : class, INativeObject, IDisposable
{
#pragma warning disable RBI0014