From 439d77f58ded56f6e5f6f2a9294e008ad6c21825 Mon Sep 17 00:00:00 2001 From: dahall Date: Thu, 19 Nov 2020 14:48:23 -0700 Subject: [PATCH] Added HEVENT handle --- PInvoke/Kernel32/SynchApi.cs | 5 + PInvoke/Shared/Handles.cs | 212 ++++++++++++++++++++++++++----------------- 2 files changed, 135 insertions(+), 82 deletions(-) diff --git a/PInvoke/Kernel32/SynchApi.cs b/PInvoke/Kernel32/SynchApi.cs index 266f1e9f..f838301d 100644 --- a/PInvoke/Kernel32/SynchApi.cs +++ b/PInvoke/Kernel32/SynchApi.cs @@ -2422,6 +2422,11 @@ namespace Vanara.PInvoke public static implicit operator SafeEventHandle(EventWaitHandle h) => new SafeEventHandle(h.Handle, false); #pragma warning restore CS0618 // Type or member is obsolete + /// Performs an implicit conversion from to . + /// The safe handle instance. + /// The result of the conversion. + public static implicit operator HEVENT(SafeEventHandle h) => h.handle; + /// Gets an invalid event handle. public static SafeEventHandle InvalidHandle => new SafeEventHandle(new IntPtr(-1), false); diff --git a/PInvoke/Shared/Handles.cs b/PInvoke/Shared/Handles.cs index ec2d0c13..0c074840 100644 --- a/PInvoke/Shared/Handles.cs +++ b/PInvoke/Shared/Handles.cs @@ -36,7 +36,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HACCEL : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -71,7 +71,7 @@ namespace Vanara.PInvoke public static bool operator ==(HACCEL h1, HACCEL h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HACCEL h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HACCEL h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -84,7 +84,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HANDLE : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -124,7 +124,7 @@ namespace Vanara.PInvoke public static bool operator ==(HANDLE h1, HANDLE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HANDLE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HANDLE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -137,7 +137,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HBITMAP : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -177,7 +177,7 @@ namespace Vanara.PInvoke public static bool operator ==(HBITMAP h1, HBITMAP h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HBITMAP h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HBITMAP h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -190,7 +190,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HBRUSH : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -230,7 +230,7 @@ namespace Vanara.PInvoke public static bool operator ==(HBRUSH h1, HBRUSH h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HBRUSH h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HBRUSH h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -243,7 +243,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential)] public struct HCOLORSPACE : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -278,7 +278,7 @@ namespace Vanara.PInvoke public static bool operator ==(HCOLORSPACE h1, HCOLORSPACE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HCOLORSPACE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HCOLORSPACE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -291,7 +291,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HCURSOR : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -326,7 +326,7 @@ namespace Vanara.PInvoke public static bool operator ==(HCURSOR h1, HCURSOR h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HCURSOR h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HCURSOR h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -339,7 +339,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDC : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -374,7 +374,7 @@ namespace Vanara.PInvoke public static bool operator ==(HDC h1, HDC h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HDC h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDC h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -387,7 +387,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDESK : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -422,7 +422,7 @@ namespace Vanara.PInvoke public static bool operator ==(HDESK h1, HDESK h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HDESK h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDESK h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -435,7 +435,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDPA : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -470,7 +470,7 @@ namespace Vanara.PInvoke public static bool operator ==(HDPA h1, HDPA h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HDPA h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDPA h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -483,7 +483,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDROP : IShellHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -518,7 +518,7 @@ namespace Vanara.PInvoke public static bool operator ==(HDROP h1, HDROP h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HDROP h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDROP h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -531,7 +531,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDSA : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -568,7 +568,7 @@ namespace Vanara.PInvoke /// Determines whether the specified , is equal to this instance. /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public override bool Equals(object obj) => obj is HDSA h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDSA h && handle == h.handle; /// Returns a hash code for this instance. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. @@ -582,7 +582,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HDWP : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -617,7 +617,7 @@ namespace Vanara.PInvoke public static bool operator ==(HDWP h1, HDWP h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HDWP h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HDWP h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -630,7 +630,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HENHMETAFILE : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -665,7 +665,55 @@ namespace Vanara.PInvoke public static bool operator ==(HENHMETAFILE h1, HENHMETAFILE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HENHMETAFILE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HENHMETAFILE h && handle == h.handle; + + /// + public override int GetHashCode() => handle.GetHashCode(); + + /// + public IntPtr DangerousGetHandle() => handle; + } + + /// Provides a handle to a synch event. + [StructLayout(LayoutKind.Sequential)] + public struct HEVENT : ISyncHandle + { + private readonly IntPtr handle; + + /// Initializes a new instance of the struct. + /// An object that represents the pre-existing handle to use. + public HEVENT(IntPtr preexistingHandle) => handle = preexistingHandle; + + /// Returns an invalid handle by instantiating a object with . + public static HEVENT NULL => new HEVENT(IntPtr.Zero); + + /// Gets a value indicating whether this instance is a null handle. + public bool IsNull => handle == IntPtr.Zero; + + /// Performs an explicit conversion from to . + /// The handle. + /// The result of the conversion. + public static explicit operator IntPtr(HEVENT h) => h.handle; + + /// Performs an implicit conversion from to . + /// The pointer to a handle. + /// The result of the conversion. + public static implicit operator HEVENT(IntPtr h) => new HEVENT(h); + + /// Implements the operator !=. + /// The first handle. + /// The second handle. + /// The result of the operator. + public static bool operator !=(HEVENT h1, HEVENT h2) => !(h1 == h2); + + /// Implements the operator ==. + /// The first handle. + /// The second handle. + /// The result of the operator. + public static bool operator ==(HEVENT h1, HEVENT h2) => h1.Equals(h2); + + /// + public override bool Equals(object obj) => obj is HEVENT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -681,7 +729,7 @@ namespace Vanara.PInvoke /// Represents an invalid handle. public static readonly HFILE INVALID_HANDLE_VALUE = new IntPtr(-1); - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -724,7 +772,7 @@ namespace Vanara.PInvoke public static bool operator ==(HFILE h1, HFILE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HFILE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HFILE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -737,7 +785,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HFONT : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -777,7 +825,7 @@ namespace Vanara.PInvoke public static bool operator ==(HFONT h1, HFONT h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HFONT h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HFONT h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -790,7 +838,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HGDIOBJ : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -875,7 +923,7 @@ namespace Vanara.PInvoke public static bool operator ==(HGDIOBJ h1, HGDIOBJ h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HGDIOBJ h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HGDIOBJ h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -888,7 +936,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HICON : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -923,7 +971,7 @@ namespace Vanara.PInvoke public static bool operator ==(HICON h1, HICON h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HICON h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HICON h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -936,7 +984,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HIMAGELIST : IShellHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -971,7 +1019,7 @@ namespace Vanara.PInvoke public static bool operator ==(HIMAGELIST h1, HIMAGELIST h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HIMAGELIST h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HIMAGELIST h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -984,7 +1032,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HINSTANCE : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1019,7 +1067,7 @@ namespace Vanara.PInvoke public static bool operator ==(HINSTANCE h1, HINSTANCE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HINSTANCE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HINSTANCE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1032,7 +1080,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HKEY : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1119,7 +1167,7 @@ namespace Vanara.PInvoke public static bool operator ==(HKEY h1, HKEY h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HKEY h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HKEY h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1132,7 +1180,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HMENU : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1167,7 +1215,7 @@ namespace Vanara.PInvoke public static bool operator ==(HMENU h1, HMENU h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HMENU h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HMENU h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1180,7 +1228,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HMETAFILE : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1215,7 +1263,7 @@ namespace Vanara.PInvoke public static bool operator ==(HMETAFILE h1, HMETAFILE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HMETAFILE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HMETAFILE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1228,7 +1276,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HMONITOR : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1263,7 +1311,7 @@ namespace Vanara.PInvoke public static bool operator ==(HMONITOR h1, HMONITOR h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HMONITOR h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HMONITOR h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1276,7 +1324,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HPALETTE : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1316,7 +1364,7 @@ namespace Vanara.PInvoke public static bool operator ==(HPALETTE h1, HPALETTE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HPALETTE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HPALETTE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1329,7 +1377,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HPEN : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1369,7 +1417,7 @@ namespace Vanara.PInvoke public static bool operator ==(HPEN h1, HPEN h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HPEN h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HPEN h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1382,7 +1430,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HPROCESS : ISyncHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1422,7 +1470,7 @@ namespace Vanara.PInvoke public static bool operator ==(HPROCESS h1, HPROCESS h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HPROCESS h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HPROCESS h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1435,7 +1483,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HPROPSHEET : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1470,7 +1518,7 @@ namespace Vanara.PInvoke public static bool operator ==(HPROPSHEET h1, HPROPSHEET h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HPROPSHEET h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HPROPSHEET h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1483,7 +1531,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HPROPSHEETPAGE : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1518,7 +1566,7 @@ namespace Vanara.PInvoke public static bool operator ==(HPROPSHEETPAGE h1, HPROPSHEETPAGE h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HPROPSHEETPAGE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HPROPSHEETPAGE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1531,7 +1579,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HRGN : IGraphicsObjectHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1571,7 +1619,7 @@ namespace Vanara.PInvoke public static bool operator ==(HRGN h1, HRGN h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HRGN h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HRGN h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1584,7 +1632,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential)] public struct HSECTION : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1619,7 +1667,7 @@ namespace Vanara.PInvoke public static bool operator ==(HSECTION h1, HSECTION h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HSECTION h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HSECTION h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1632,7 +1680,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential)] public struct HTASK : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1667,7 +1715,7 @@ namespace Vanara.PInvoke public static bool operator ==(HTASK h1, HTASK h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HTASK h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HTASK h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1680,7 +1728,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HTHEME : IHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1715,7 +1763,7 @@ namespace Vanara.PInvoke public static bool operator ==(HTHEME h1, HTHEME h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HTHEME h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HTHEME h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1728,7 +1776,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HTHREAD : ISyncHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1763,7 +1811,7 @@ namespace Vanara.PInvoke public static bool operator ==(HTHREAD h1, HTHREAD h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HTHREAD h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HTHREAD h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1776,7 +1824,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HTHUMBNAIL : IShellHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1811,7 +1859,7 @@ namespace Vanara.PInvoke public static bool operator ==(HTHUMBNAIL h1, HTHUMBNAIL h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HTHUMBNAIL h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HTHUMBNAIL h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1824,7 +1872,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HTOKEN : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1859,7 +1907,7 @@ namespace Vanara.PInvoke public static bool operator ==(HTOKEN h1, HTOKEN h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HTOKEN h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HTOKEN h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1872,7 +1920,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HWINSTA : IKernelHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1907,7 +1955,7 @@ namespace Vanara.PInvoke public static bool operator ==(HWINSTA h1, HWINSTA h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HWINSTA h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HWINSTA h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1920,7 +1968,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct HWND : IUserHandle { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -1973,7 +2021,7 @@ namespace Vanara.PInvoke public static bool operator ==(HWND h1, HWND h2) => h1.Equals(h2); /// - public override bool Equals(object obj) => obj is HWND h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is HWND h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -1986,7 +2034,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct PACE : ISecurityObject { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -2009,7 +2057,7 @@ namespace Vanara.PInvoke public static implicit operator PACE(IntPtr h) => new PACE(h); /// - public override bool Equals(object obj) => obj is PACE h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is PACE h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -2022,7 +2070,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct PACL : ISecurityObject { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -2045,7 +2093,7 @@ namespace Vanara.PInvoke public static implicit operator PACL(IntPtr h) => new PACL(h); /// - public override bool Equals(object obj) => obj is PACL h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is PACL h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -2058,7 +2106,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct PSECURITY_DESCRIPTOR : ISecurityObject { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -2081,7 +2129,7 @@ namespace Vanara.PInvoke public static implicit operator PSECURITY_DESCRIPTOR(IntPtr h) => new PSECURITY_DESCRIPTOR(h); /// - public override bool Equals(object obj) => obj is PSECURITY_DESCRIPTOR h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is PSECURITY_DESCRIPTOR h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode(); @@ -2094,7 +2142,7 @@ namespace Vanara.PInvoke [StructLayout(LayoutKind.Sequential), DebuggerDisplay("{handle}")] public struct PSID : ISecurityObject { - private IntPtr handle; + private readonly IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. @@ -2117,7 +2165,7 @@ namespace Vanara.PInvoke public static implicit operator PSID(IntPtr h) => new PSID(h); /// - public override bool Equals(object obj) => obj is PSID h ? handle == h.handle : false; + public override bool Equals(object obj) => obj is PSID h && handle == h.handle; /// public override int GetHashCode() => handle.GetHashCode();