[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.
Proposal of UnmanagedType Specialization
Then serializer use
ReadUnmanaged/WriteUnmanaged
. Source generator can know whether generic T is unmanaged by ITypeSymbol.IsUnmanagedType.