Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmanagedType Specialization #216

Closed
Akeit0 opened this issue Jan 20, 2024 · 1 comment
Closed

UnmanagedType Specialization #216

Akeit0 opened this issue Jan 20, 2024 · 1 comment

Comments

@Akeit0
Copy link

Akeit0 commented Jan 20, 2024

Proposal of UnmanagedType Specialization

[MemoryPackable]
[Serializable]
public partial class Data<T>where T:unmanaged
{
   [MemoryPackUnmanaged]
    public T Value { get; protected set; } = default;
}

Then serializer use ReadUnmanaged/WriteUnmanaged.
Source generator can know whether generic T is unmanaged by ITypeSymbol.IsUnmanagedType.

@hadashiA
Copy link
Contributor

hadashiA commented Mar 8, 2024

Thanks for the suggestion.
For the benefits, there seem to be a lot of difficulties.

  • The default LayoutKind for class seems to be different from struct.
  • Also, MemoryPack provides higher version compatibility for classes than structs.

@hadashiA hadashiA closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants