From bef4a869bae44744b52a3a7fd4407cb236772682 Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 19 Feb 2019 14:16:44 -0700 Subject: [PATCH] Added SafeHANDLE to HANDLE implicit operator and adjusted SafeHANDLE == operator to address `default` values (#40). --- PInvoke/Shared/Handles.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PInvoke/Shared/Handles.cs b/PInvoke/Shared/Handles.cs index b3332cad..e5f3ae4e 100644 --- a/PInvoke/Shared/Handles.cs +++ b/PInvoke/Shared/Handles.cs @@ -104,6 +104,11 @@ namespace Vanara.PInvoke /// The result of the conversion. public static implicit operator HANDLE(IntPtr h) => new HANDLE(h); + /// Performs an implicit conversion from to . + /// The h. + /// The result of the conversion. + public static implicit operator HANDLE(SafeHANDLE h) => new HANDLE(h.DangerousGetHandle()); + /// Implements the operator !=. /// The first handle. /// The second handle. @@ -1959,7 +1964,7 @@ namespace Vanara.PInvoke /// The first handle. /// The second handle. /// The result of the operator. - public static bool operator ==(SafeHANDLE h1, SafeHANDLE h2) => h1 is null || h2 is null ? false : h1.Equals(h2); + public static bool operator ==(SafeHANDLE h1, SafeHANDLE h2) => h1?.Equals(h2) ?? h2 is null; /// Determines whether the specified , is equal to this instance. /// The to compare with this instance.