From 70a9c278d2aa25ee8fbb797986532b7d93528863 Mon Sep 17 00:00:00 2001 From: dahall Date: Thu, 10 Sep 2020 10:37:16 -0600 Subject: [PATCH] Changed SafeDRT_DATA fields to properties. --- PInvoke/Drt/Drt.cs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/PInvoke/Drt/Drt.cs b/PInvoke/Drt/Drt.cs index 42afce34..9f3dcf60 100644 --- a/PInvoke/Drt/Drt.cs +++ b/PInvoke/Drt/Drt.cs @@ -2345,23 +2345,23 @@ namespace Vanara.PInvoke public class SafeDRT_DATA : IDisposable { /// A DWORD variable that contains the count, in bytes, of data. - public readonly uint cb; + private uint _cb; /// A pointer to the data buffer. - public readonly IntPtr pb; + private IntPtr _pb; /// Initializes a new instance of the class. /// The size, in bytes, to allocate. public SafeDRT_DATA(int size) { - cb = (uint)size; + _cb = (uint)size; if (size > 0) - pb = MemMethods.AllocMem(size); + _pb = MemMethods.AllocMem(size); } /// Initializes a new instance of the class. /// The bytes to copy into the blob. - public SafeDRT_DATA(byte[] bytes) : this(bytes?.Length ?? 0) => Marshal.Copy(bytes, 0, pb, bytes.Length); + public SafeDRT_DATA(byte[] bytes) : this(bytes?.Length ?? 0) => Marshal.Copy(bytes, 0, _pb, bytes.Length); /// Initializes a new instance of the class with a string. /// The string value. @@ -2372,25 +2372,31 @@ namespace Vanara.PInvoke private SafeDRT_DATA(IntPtr handle, int size) { - pb = handle; - cb = (uint)size; + _pb = handle; + _cb = (uint)size; } + /// A DWORD variable that contains the count, in bytes, of data. + public uint cb => _cb; + + /// A pointer to the data buffer. + public IntPtr pb => _pb; + /// Represents an empty instance of a blob. public static readonly SafeDRT_DATA Empty = new SafeDRT_DATA(IntPtr.Zero, 0); /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. public void Dispose() { - MemMethods.FreeMem(pb); - pb = IntPtr.Zero; - cb = 0; + MemMethods.FreeMem(_pb); + _pb = IntPtr.Zero; + _cb = 0; } /// Performs an implicit conversion from to . /// The safe data. /// The resulting instance from the conversion. - public static implicit operator DRT_DATA(SafeDRT_DATA safeData) => new DRT_DATA { cb = safeData.cb, pb = safeData.pb }; + public static implicit operator DRT_DATA(SafeDRT_DATA safeData) => new DRT_DATA { cb = safeData._cb, pb = safeData._pb }; /// Allocates from unmanaged memory sufficient memory to hold an object of type T. /// Native type