Hi all,

I have a simple class with reference to parent object. All objects are in 
one list (even parent objects). Is it possible to keep references 
references after deserialization? 

In my code I have something like this:


    [ProtoContract]
    public class ProtoItem
    {
        [ProtoMember(1)]
        public int Value { get; set; }

        [ProtoMember(2, AsReference = true)]
        public ProtoItem BaseItem { get; set; }
    }

And main looks like that:

        static void Main()
        {
            var itemParent = new ProtoItem { Value = 1 };
            var item2 = new ProtoItem { Value = 2, BaseItem = itemParent };
            var item3 = new ProtoItem { Value = 3, BaseItem = itemParent };

            var parentListToWrite = new List<ProtoItem> {itemParent, item2, 
item3};

            const string file = "protofile.txt";
            try { File.Delete(file); }
            catch { };

            using (var fs = File.OpenWrite(file)) { Serializer.Serialize(fs,    
                 parentListToWrite); }

        List<ProtoItem> readList;
        using (var fs = File.OpenRead(file)) { readList = 
            Serializer.Deserialize<List<ProtoItem>>(fs); }

        if (readList[0] == readList[2].BaseItem)
        {
            //how to make it equal?
        }
        if (readList[0] == readList[1].BaseItem)
        {
            //how to make it equal?
        }
    }

Is it possible to deserialize that if conditions works?

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to