From a4fee226c5713542ac6a182d50132d67401d94f2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 19 Feb 2026 12:54:51 -0800 Subject: [PATCH] Change WindowsRuntimeObjectReference methods to internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce the public surface of WindowsRuntimeObjectReference by changing several API access modifiers from public to internal. Updated AsUnsafe/TryAs/TryAsUnsafe overloads in WindowsRuntimeObjectReference.Helpers.cs and lifecycle methods (GetReferenceTrackerPtrUnsafe, AddRefUnsafe, TryAddRefUnsafe, ReleaseUnsafe) in WindowsRuntimeObjectReference.Lifecycle.cs. No behavioral changes intended — only visibility/encapsulation adjustments to restrict these unsafe/lifecycle operations to internal consumers. --- .../WindowsRuntimeObjectReference.Helpers.cs | 12 ++++++------ .../WindowsRuntimeObjectReference.Lifecycle.cs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Helpers.cs b/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Helpers.cs index ca99a22944..c4c0430e5c 100644 --- a/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Helpers.cs +++ b/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Helpers.cs @@ -55,7 +55,7 @@ public WindowsRuntimeObjectReference As(in Guid iid) /// The COM object pointer for the requested interface. /// Thrown if the current instance has been disposed. /// Thrown if the QueryInterface call fails for any reason. - public void* AsUnsafe(in Guid iid) + internal void* AsUnsafe(in Guid iid) { AsUnsafe(in iid, out void* pv); @@ -69,13 +69,13 @@ public WindowsRuntimeObjectReference As(in Guid iid) /// The resulting COM object pointer to retrieve. /// Thrown if the current instance has been disposed. /// Thrown if the QueryInterface call fails for any reason. - public void AsUnsafe(in Guid iid, out void* ppv) + internal void AsUnsafe(in Guid iid, out void* ppv) { TryAsNative(in iid, out ppv).Assert(); } /// - public void AsUnsafe(in Guid iid, out nint ppv) + internal void AsUnsafe(in Guid iid, out nint ppv) { TryAsNative(in iid, out ppv).Assert(); } @@ -87,7 +87,7 @@ public void AsUnsafe(in Guid iid, out nint ppv) /// The resulting instance for the requested interface. /// Whether the requested interface was retrieved successfully. /// Thrown if the current instance has been disposed. - public bool TryAs(in Guid iid, [NotNullWhen(true)] out WindowsRuntimeObjectReference? objectReference) + internal bool TryAs(in Guid iid, [NotNullWhen(true)] out WindowsRuntimeObjectReference? objectReference) { HRESULT hresult = DerivedTryAsNative(in iid, out objectReference); @@ -101,7 +101,7 @@ public bool TryAs(in Guid iid, [NotNullWhen(true)] out WindowsRuntimeObjectRefer /// The resulting COM pointer for the requested interface. /// Whether the requested interface was retrieved successfully. /// Thrown if the current instance has been disposed. - public bool TryAsUnsafe(in Guid iid, out void* ppv) + internal bool TryAsUnsafe(in Guid iid, out void* ppv) { HRESULT hresult = TryAsNative(in iid, out ppv); @@ -109,7 +109,7 @@ public bool TryAsUnsafe(in Guid iid, out void* ppv) } /// - public bool TryAsUnsafe(in Guid iid, out nint ppv) + internal bool TryAsUnsafe(in Guid iid, out nint ppv) { HRESULT hresult = TryAsNative(in iid, out ppv); diff --git a/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Lifecycle.cs b/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Lifecycle.cs index 7c96427a56..956b831ba2 100644 --- a/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Lifecycle.cs +++ b/src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.Lifecycle.cs @@ -99,7 +99,7 @@ public void Dispose() /// the current object. Callers must call and . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void* GetReferenceTrackerPtrUnsafe() + internal void* GetReferenceTrackerPtrUnsafe() { return _referenceTrackerPtr; } @@ -109,7 +109,7 @@ public void Dispose() /// /// Thrown if the current instance has been disposed. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddRefUnsafe() + internal void AddRefUnsafe() { ObjectDisposedException.ThrowIf(!TryAddRefUnsafe(), this); } @@ -119,7 +119,7 @@ public void AddRefUnsafe() /// /// Whether the managed reference count has been increased successfully. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool TryAddRefUnsafe() + internal bool TryAddRefUnsafe() { bool success = true; @@ -220,7 +220,7 @@ private void DisposeUnsafe() /// /// Calls to should always exactly match calls to . /// - public void ReleaseUnsafe() + internal void ReleaseUnsafe() { // To release, we can simply do an interlocked decrement on the reference tracking // mask. Each caller is guaranteed to only call this method once (the contract states to only