using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.Windows; namespace ComputeSharp.D2D1.Uwp.Extensions; /// /// Helper methods for working with the type. /// internal static class ComPtrExtensions { /// /// Checks whether two values have the same underlying COM object. /// /// The type of the first value to check. /// The type of the second value to check. /// The first object to compare. /// The second object to compare. /// Whether and point to the same COM object. public static unsafe bool IsSameInstance(this in ComPtr left, in ComPtr right) where T : unmanaged where U : unmanaged { if (left.Get() == right.Get()) { return true; } if (left.Get() is null || right.Get() is null) { return false; } using ComPtr leftUnknown = default; using ComPtr rightUnknown = default; left.CopyTo(leftUnknown.GetAddressOf()).Assert(); right.CopyTo(rightUnknown.GetAddressOf()).Assert(); return leftUnknown.Get() == rightUnknown.Get(); } }