Skip to content

Instantly share code, notes, and snippets.

@mgravell
Created September 20, 2022 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgravell/b861a5d92afc113d3b3e7276fdb98932 to your computer and use it in GitHub Desktop.
Save mgravell/b861a5d92afc113d3b3e7276fdb98932 to your computer and use it in GitHub Desktop.
protected override bool TryGetArray(out ArraySegment<T> segment)
{
if (typeof(T) == typeof(byte))
{
return MemoryMarshal.TryGetArray(Unsafe.As<Memory<byte>, Memory<T>>(ref Unsafe.AsRef(in this.memory)), out segment);
}
else
{
segment = default;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment