From f99c9465cc8416b57f33cbcf417697d7dfb72e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Wed, 24 Apr 2019 18:21:53 +0800 Subject: [PATCH] Add warnings for ref values. Fixes #1. --- src/Berrysoft.Unsafe/ByReference.cs | 1 + src/Berrysoft.Unsafe/Pointer.cs | 1 + src/Berrysoft.Unsafe/UnsafeMethods.cs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/Berrysoft.Unsafe/ByReference.cs b/src/Berrysoft.Unsafe/ByReference.cs index 129b949..b91a31d 100644 --- a/src/Berrysoft.Unsafe/ByReference.cs +++ b/src/Berrysoft.Unsafe/ByReference.cs @@ -16,6 +16,7 @@ namespace Berrysoft.Unsafe private readonly void* _ptr; /// /// Initialize a with a reference. + /// Note: the storage of value should be pinned. /// /// The reference. [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Berrysoft.Unsafe/Pointer.cs b/src/Berrysoft.Unsafe/Pointer.cs index 41a9aad..de1a43a 100644 --- a/src/Berrysoft.Unsafe/Pointer.cs +++ b/src/Berrysoft.Unsafe/Pointer.cs @@ -38,6 +38,7 @@ public Pointer(IntPtr ptr) } /// /// Initialize a with a reference. + /// Note: the storage of value should be pinned. /// /// The reference. [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Berrysoft.Unsafe/UnsafeMethods.cs b/src/Berrysoft.Unsafe/UnsafeMethods.cs index 1a70191..10b6e04 100644 --- a/src/Berrysoft.Unsafe/UnsafeMethods.cs +++ b/src/Berrysoft.Unsafe/UnsafeMethods.cs @@ -18,6 +18,7 @@ public unsafe static class UnsafeMethods public static int GetSize() => SizeOf(); /// /// Get a with a reference. + /// Note: the storage of value should be pinned. /// /// Type of the pointer pointed to. /// The reference. @@ -47,6 +48,7 @@ public static Pointer PointerOf(string str) } /// /// Get a with a reference. + /// Note: the storage of value should be pinned. /// /// Type of the pointer pointed to. /// The reference. @@ -55,6 +57,7 @@ public static Pointer PointerOf(string str) public static ByReference ByReference(ref T value) => new ByReference(ref value); /// /// Get a with a readonly reference. + /// Note: the storage of value should be pinned. /// /// Type of the pointer pointed to. /// The reference.