Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support by-ref-like (ref struct) parameter types such as Span<T> and ReadOnlySpan<T> #663

Assignees
@stakx

Description

DynamicProxy does not currently support those because by-ref-like values cannot be boxed to be put in the object[] IInvocation.Arguments array.

(削除) I haven't yet been able to think of a general way how all by-ref-like types (including user-defined ones) could be supported, ecause of their various limitations. If anyone has ideas, I'd be interested in hearing them! (削除ここまで)

(削除) However, it might be fairly easy to at least add support for Span<T> and ReadOnlySpan<T> specifically. Those types are becoming more and more common in the .NET FCL, so while not an ideal solution, it might still be sufficient for most use cases: (削除ここまで)

(削除) We could introduce a new type in DynamicProxy's namespace: (削除ここまで)

public interface ISpanMarshaller // NOTE: outdated API proposal!
{
 object BoxSpan<T>(Span<T> span);
 object BoxReadOnlySpan<T>(ReadOnlySpan<T> readOnlySpan);
 ReadOnlySpan<T> UnboxReadOnlySpan<T>(object boxedReadOnlySpan);
 Span<T> UnboxSpan<T>(object boxedSpan);
}

(削除) Then we could introduce a new property to ProxyGenerationOptions, ISpanMarshaller SpanMarshaller { get; set; }, which would get injected into generated proxies so they could use it to transfer spans into and out of the object[] IInvocation.Arguments array. (削除ここまで)

(削除) I don't really like an addition that deals with two very specific types, but they are becoming more and more common, and I haven't yet been able to come up with a more general mechanism. (削除ここまで)

Update

See the PR linked further down for an updated proposal that supports arbitrary by-ref-like types, including user-defined ones.

Opinions, or alternate ideas, anyone?

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /