diff --git a/Core/Extensions/InteropExtensions.cs b/Core/Extensions/InteropExtensions.cs
index 01fa06f9..64cc3ccf 100644
--- a/Core/Extensions/InteropExtensions.cs
+++ b/Core/Extensions/InteropExtensions.cs
@@ -15,12 +15,23 @@ namespace Vanara.Extensions
/// The allocated memory pointer.
/// The allocated memory pointer to copy to.
/// The number of bytes to copy from to .
- public static unsafe void CopyTo(this IntPtr ptr, IntPtr dest, long length)
+ public static void CopyTo(this IntPtr ptr, IntPtr dest, long length) => CopyTo(ptr, 0L, dest, length);
+
+ /// Copies the number of specified bytes from one unmanaged memory block to another.
+ /// The allocated memory pointer.
+ /// The offset from at which to start the copying.
+ /// The allocated memory pointer to copy to.
+ /// The number of bytes to copy from to .
+ public static void CopyTo(this IntPtr source, long start, IntPtr dest, long length)
{
- var psrc = (byte*)ptr;
- var pdest = (byte*)dest;
- for (var i = 0; i < length; i++, psrc++, pdest++)
- *pdest = *psrc;
+ if (start < 0 || length < 0) throw new ArgumentOutOfRangeException();
+ if (source == IntPtr.Zero || dest == IntPtr.Zero) throw new ArgumentNullException();
+ unsafe
+ {
+ byte* psrc = (byte*)source + start, pdest = (byte*)dest;
+ for (long i = 0; i < length; i++, psrc++, pdest++)
+ *pdest = *psrc;
+ }
}
///