Skip to content

Instantly share code, notes, and snippets.

@Sergio0694
Last active September 25, 2019 11:55
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 Sergio0694/cd3a342a2ce3db122c4f652f9ad93619 to your computer and use it in GitHub Desktop.
Save Sergio0694/cd3a342a2ce3db122c4f652f9ad93619 to your computer and use it in GitHub Desktop.
public static unsafe (object[] References, byte[] Bytes) GetData(
Delegate instance, DataLoader loader,
int referenceCount, int byteSize)
{
// Reference and byte array
object[] refs = ArrayPool<object>.Shared.Rent(referenceCount);
byte[] bytes = ArrayPool<byte>.Shared.Rent(byteSize);
ref object r0 = ref refs.Length > 0 ? ref refs[0] : ref Unsafe.AsRef<object>(null);
ref byte r1 = ref bytes.Length > 0 ? ref bytes[0] : ref Unsafe.AsRef<byte>(null);
// Invoke the dynamic method to extract the captured data
loader(instance.Target, ref r0, ref r1);
return (refs, bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment