From 5548ff6c71158170a36beba53b5e0097c627c8a1 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 10 Apr 2019 13:11:06 -0600 Subject: [PATCH] Changed generic constraint on Write methods to struct instead of unmanaged --- Core/InteropServices/NativeMemoryStream.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Core/InteropServices/NativeMemoryStream.cs b/Core/InteropServices/NativeMemoryStream.cs index f06a6cde..23368ba6 100644 --- a/Core/InteropServices/NativeMemoryStream.cs +++ b/Core/InteropServices/NativeMemoryStream.cs @@ -49,9 +49,10 @@ namespace Vanara.InteropServices /// Initializes a new instance of the class with a pointer and allows for dynamic growth. /// The pointer to unmanaged, preallocated memory. /// The bytes allocated to . - public NativeMemoryStream(IntPtr unmanagedPtr, long bytesAllocated) + /// The mode of file access to the native memory stream. + public NativeMemoryStream(IntPtr unmanagedPtr, long bytesAllocated, FileAccess access = FileAccess.Read) { - access = FileAccess.Read; + this.access = access; chunkSize = 0; Pointer = unmanagedPtr; MaxCapacity = capacity = bytesAllocated; @@ -321,7 +322,7 @@ namespace Vanara.InteropServices /// Writes the specified value into the stream. /// The type of the value. /// The value. - public void Write(in T value) where T : unmanaged => WriteObject(value); + public void Write(in T value) where T : struct => WriteObject(value); /// Writes the specified string into the stream. /// The string value. @@ -340,7 +341,7 @@ namespace Vanara.InteropServices /// The type of the array item. /// The items. /// Write values as a referenced array. - public void Write(IEnumerable items, bool byRef = false) where T : unmanaged + public void Write(IEnumerable items, bool byRef = false) where T : struct { if (access == FileAccess.Read) throw new NotSupportedException(); if (items == null) return;