Force protobuf-net ignore IEnumerable / ICollection interfaces

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

In this particular scenario, I want the fields marked as [ProtoMember] to be serialized.


I am currently moving from using protobuf-net v1 to using v2. I have a specific structure that is now serializing incorrectly due to a change. It looks something like this:

[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 smooth out file paths such as "C: \ happy.txt" "C: \ history.txt", to something more than

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

The structure eliminates redundancy in the path lines. Thus, I really do not want the FileTree class to be serialized through IEnumerable functions, because then it is simply stored as "C: \ happy.txt", "C: \ history.txt", etc. Right now, in the serialization of the FileTree object, every path is printed completely.


EDIT: The last thing I should mention is that I have the On_Deserialization function in FileTree, which is labeled [ProtoAfterDeserialization]. I set a breakpoint in the function, but it does not fall. Is this related to how this class is serialized?

+6
source share
1 answer
 [ProtoContract(IgnoreListHandling = true)] public class FileTree : ICollection<FilePath> ... { ... } 

must do it. I honestly do not think that I considered callbacks in lists, since they are processed as much as in subjects, but with the above, which should work. Let me know if this is not the case.

From the intellisense documentation:

Gets or sets a value indicating that this type should NOT be considered as a list, even if it has the familiar characteristics of a list (enumerated, added, etc.).

+7
source

Source: https://habr.com/ru/post/902967/


All Articles