c# – ProtoBuf-Net错误消息 – “不支持嵌套或锯齿状列表和数组”

c# – ProtoBuf-Net错误消息 – “不支持嵌套或锯齿状列表和数组”,第1张

概述主要目标是动态填充Dictionary对象并使用Protobuf-net对其进行序列化,并将其通过WCF服务发送到客户端. @marc你能告诉我一个代码示例,当我尝试使用Protobuf-net进行序列化时,如何解决错误“不支持嵌套锯齿状列表和数组”. [Serializable][ProtoContract]public class DynamicWrapper{ [ProtoM 主要目标是动态填充Dictionary对象并使用Protobuf-net对其进行序列化,并将其通过WCF服务发送到客户端.

@marc你能告诉我一个代码示例,当我尝试使用Protobuf-net进行序列化时,如何解决错误“不支持嵌套或锯齿状列表和数组”.

[Serializable][ProtoContract]public class DynamicWrapper{    [ProtoMember(1)]    public List<Dictionary<string,string>> Items { get; set; }    public DynamicWrapper()    {        Items = new  List<Dictionary<string,string>>();    }}public class Service1 : IService1{    public byte[] GetData(string sVisibleColumnList)    {        DynamicWrapper DW = new DynamicWrapper();        Dictionary<string,string> d = new Dictionary<string,string>();        d.Add("CUSIP","123456");        DW.Items.Add(d);        d = new Dictionary<string,string>();        d.Add("ISIN","456789");        DW.Items.Add(d);        var ms = new MemoryStream();        var model = ProtoBuf.Meta.RuntimeTypeModel.Default;        model.Serialize(ms,DW);        Serializer.Serialize <DynamicWrapper>(ms,DW);        return ms.GetBuffer();    }}
解决方法 您可以将Dictionary包装到单独的类中.然后使用这些对象的列表.
[ProtoContract]public class DynamicWrapper{    [ProtoMember(1)]    public List<DictWrapper> Items { get; set; }    public DynamicWrapper()    {        Items = new  List<DictWrapper>();    }}[ProtoContract]public class DictWrapper{    [ProtoMember(1)]    public Dictionary<string,string> Dictionary { get; set; }}
总结

以上是内存溢出为你收集整理的c# – ProtoBuf-Net错误消息 – “不支持嵌套或锯齿状列表和数组”全部内容,希望文章能够帮你解决c# – ProtoBuf-Net错误消息 – “不支持嵌套或锯齿状列表和数组”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1246496.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存