[API Proposal] Create ReadOnlySpanMarshaller<T, TUnmanaged>.ManagedToUnmanagedOut marshaller #101136
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Runtime.InteropServices
blocking
Marks issues that we want to fast track in order to unblock other important work
Milestone
Background and motivation
To address #96525, we can provide a marshaller for
ReadOnlySpan<T>
forManagedToUnmanagedOut
direction. We have marshallers for UnmanagedToManagedOut and ManagedToUnmanagedIn. This API wasn't created previously due to the assumption that the managedReadOnlySpan<T>
would need to be written to in generated marshaling code, but that isn't strictly necessary for stateful marshallers. This API would allowLibraryImport
methods to returnReadOnlySpan<T>
without creating a new marshaller or specifying the marshaller type in the method definition.API Proposal
API Usage
The API would primarily be used in code generated by the LibraryImport generator to unmarshal a native array into a managed
ReadOnlySpan<T>
when a method returns aReadOnlySpan<T>
or has anout
parameter of typeReadOnlySpan<T>
.Alternative Designs
A workaround is to create a LibraryImport that returns another built-in collection type and create a wrapper that converts the returned collection into a
ReadOnlySpan<T>
, or use hand-written marshalling for the method.Risk
Minimal. We already provide marshallers for
ReadOnlySpan<T>
to pass a parameter in, and we have marshallers for other collections to return a value from a native method, so this is not introducing a new concept.The text was updated successfully, but these errors were encountered: