Cysharp / MemoryPack

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

How to define custom collection with shared property member #293

Open alexluozf opened 4 months ago

alexluozf commented 4 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 4 months ago

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