Table of Contents

Class RefHandleMarshaller

Namespace
Ubiquity.NET.InteropHelpers
Assembly
Ubiquity.NET.InteropHelpers.dll

Performs custom marshalling of handle arrays as in parameters

public static class RefHandleMarshaller
Inheritance
RefHandleMarshaller
Inherited Members

Remarks

Sadly, the built-in support for safe handles doesn't include arrays of the elements as `in` parameters while still retaining ownership (That is, `ref` semantics). Worse, the documentation for source generator custom marshallers (especially for arrays) is so poor that it wasn't plausible to implement this support as a custom marshaller.

Instead these APIs are declared to simplify and control the marshalling as safely as possible. Callers must use either WithNativePointer<THandle>(THandle[], VoidOp) or WithNativePointer<THandle, TRetVal>(THandle[], ReturningOp<TRetVal>) to allocate, build, call an operation delegate, and then release the native array [optionally returning a result]. That is, the hard and tedious work of allocating, copying the managed array and pinning the array for native consumption is ALL handled in the methods provided by this class.

Methods

WithNativePointer<THandle>(THandle[], VoidOp)

Marshals an array SafeHandle to a native pointer (as an array of nint)

WithNativePointer<THandle, TRetVal>(THandle[], ReturningOp<TRetVal>)

Marshals an array SafeHandle to a native pointer (as an array of nint)