力protobuf网忽略了IEnumerable / ICollection的接口 [英] Force protobuf-net to ignore IEnumerable/ICollection interfaces

查看:186
本文介绍了力protobuf网忽略了IEnumerable / ICollection的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到protobuf网的V2忽视的事实,我的类实现的ICollection,IEnumerable的,等等?

有关此特定情况下,我只希望我已经标记为[ProtoMember]字段被序列化。


我目前在使用protobuf网v1的使用v2的转换的过程。我有一个特殊的结构,这是现在序列正确,因为变化。它看起来像下面这样:

  [ProtoContract]
公共类文件树:ICollection的< FILEPATH>中的IEnumerable< FILEPATH>中的IEnumerable,INotifyCollectionChanged,INotifyPropertyChanged的{

    私人FileTreeNode _root;

    [ProtoMember(1)]
    公共FileTreeNode根{
        {返回_root; }
        集合{_root =价值; }
    }
}
 

该文件树类写倒塌像文件路径C:\ happy.txtC:\ history.txt到更多的东西像

 C:\ H
└───appy.txt
└───istory.txt
 

的结构消除冗余的路径串。所以,我真的不想要的文件树类被通过IEnumerable的功能,因为那只是被存储为序列C:\ happy.txt:现在C:\ history.txt等,在系列化一个文件树对象,每条路径都让打印出完整的。


编辑:最后一件事我应该提到 - 我在文件树的On_Deserialization功能,将被标[ProtoAfterDese​​rialization。我把一个断点的功能,但它没有击中。这是与此相关的类被序列化的方式?

解决方案

  [ProtoContract(IgnoreListHandling =真)
公共类文件树:ICollection的< FILEPATH> ...
{...}
 

应该这样做。老实说,我不认为我已经考虑回调的名单,因为他们是如此的处理非常不同的实体,但与上述应工作。让我知道,如果它没有。

从智能感知文档:

  

获取或设置一个值,表明这种类型不应该被视为一个列表,即使它有熟悉的列表类似的特性(枚举,加等)

How can I get v2 of protobuf-net to ignore the fact that my class implements ICollection, IEnumerable, etc?

For this particular scenario, I only want the fields I have flagged as [ProtoMember] to be serialized.


I am currently in the process of converting from using protobuf-net v1 to using v2. I have a particular structure which is now serializing incorrectly because of the change. It looks something like the following:

[ProtoContract]
public class FileTree : ICollection<FilePath>, IEnumerable<FilePath>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged {

    private FileTreeNode _Root;

    [ProtoMember (1)]
    public FileTreeNode Root {
        get { return _Root; }
        set { _Root = value; }
    }
}

The FileTree class was written to collapse file paths like "C:\happy.txt" "C:\history.txt" into something more like

"C:\h"
└─── "appy.txt"
└─── "istory.txt"

The structure eliminates redundancy in the path strings. So, I really don't want the FileTree class being serialized via the IEnumerable functions because then it just gets stored as "C:\happy.txt", "C:\history.txt", etc. Right now, in the serialization of a FileTree object, each path is getting print out in full.


EDIT: One last thing I should mention -- I have an On_Deserialization function in FileTree which is tagged with [ProtoAfterDeserialization]. I put a breakpoint in the function, but it is not getting hit. Is this related to the way this class is being serialized?

解决方案

[ProtoContract(IgnoreListHandling = true)]
public class FileTree : ICollection<FilePath> ...
{ ... }

should do it. I honestly don't think I've considered callbacks on lists, since they are handled so very different to entities, but with the above that should work. Let me know if it doesn't.

From the intellisense documentation:

Gets or sets a value indicating that this type should NOT be treated as a list, even if it has familiar list-like characteristics (enumerable, add, etc)

这篇关于力protobuf网忽略了IEnumerable / ICollection的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆