Cysharp / MemoryPack

Zero encoding extreme performance binary serializer for C# and Unity.
MIT License
3.37k stars 204 forks source link

How to define custom collection with shared property member #293

Open alexluozf opened 6 months ago

alexluozf commented 6 months ago

Hello,

How to define custom collection with shared property member? Please kindly see attached, property "Data" cannot be serialization/deserialization.

Thanks a lot B/r Alex Luo

using MemoryPack; using System.Collections;

namespace MemoryPackCollectionsTest { [MemoryPackable(GenerateType.Collection)] public partial class MyDictionary : Dictionary<string, MyDictionary> where T : INodeData {

region Properties

    [MemoryPackOrder(0)]
    public T? Data { get; set; }

    #endregion

    #region Constructor

    [MemoryPackConstructor]
    public MyDictionary()
    { }

    public MyDictionary(T data)
    {
        Data = data;
    }

    #endregion

}

}

alexluozf commented 6 months ago

Sorry, I don't know why “T” be deleted while copy & paste. sc

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.