diff --git a/Core/InteropServices/SafeMemStruct.cs b/Core/InteropServices/SafeMemStruct.cs index b3c379db..6d93a83c 100644 --- a/Core/InteropServices/SafeMemStruct.cs +++ b/Core/InteropServices/SafeMemStruct.cs @@ -87,21 +87,20 @@ namespace Vanara.InteropServices /// 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) => ReferenceEquals(this, obj) - ? true - : (obj switch - { - null => false, - SafeMemStruct ms => Equals((TStruct?)this, (TStruct?)ms), - TStruct s => Equals(s), - SafeAllocatedMemoryHandle m => m.DangerousGetHandle() == handle, - _ => false, - }); + public override bool Equals(object obj) => ReferenceEquals(this, obj) || + (obj switch + { + null => false, + SafeMemStruct ms => Equals((TStruct?)this, (TStruct?)ms), + TStruct s => Equals(s), + SafeAllocatedMemoryHandle m => m.DangerousGetHandle() == handle, + _ => false, + }); /// Indicates whether the current object is equal to another object of the same type. /// An object to compare with this object. /// true if the current object is equal to the parameter; otherwise, false. - public bool Equals(TStruct other) => !HasValue ? false : EqualityComparer.Default.Equals(handle.ToStructure(Size), other); + public bool Equals(TStruct other) => HasValue && EqualityComparer.Default.Equals(handle.ToStructure(Size), other); /// 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. @@ -158,6 +157,9 @@ namespace Vanara.InteropServices [ExcludeFromCodeCoverage] public SafeCoTaskMemStruct(IntPtr ptr, bool ownsHandle = true, SizeT allocatedBytes = default) : base(ptr, ownsHandle, allocatedBytes) { } + /// Represents the equivalent of this class instances. + public static readonly SafeCoTaskMemStruct Null = new SafeCoTaskMemStruct(IntPtr.Zero, false); + /// Performs an implicit conversion from to . /// The value of the instance or . /// The resulting instance from the conversion. @@ -187,6 +189,9 @@ namespace Vanara.InteropServices [ExcludeFromCodeCoverage] public SafeHGlobalStruct(IntPtr ptr, bool ownsHandle = true, SizeT allocatedBytes = default) : base(ptr, ownsHandle, allocatedBytes) { } + /// Represents the equivalent of this class instances. + public static readonly SafeHGlobalStruct Null = new SafeHGlobalStruct(IntPtr.Zero, false); + /// Performs an implicit conversion from to . /// The value of the instance or . /// The resulting instance from the conversion.