anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

IgnoreListHandling mechanics #287

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
1. Create a type A that implements IEnumerable<string>, but is marked with 
IgnoreListHandling.
2. Create a type B that implements IEnumerable<A>.
3. Create a type C that contains an instance of type B.
4. Try to serialize an instance of C.

What is the expected output? What do you see instead?
Instead of serializing anything, a NotSupportedException is thrown. The 
IgnoreListHandling value does not seem to be used. While investigating I ran 
into some other potential issues with list handling(see attachment).

What version of the product are you using? On what operating system?
protobuf-net 2.0.0.480, .Net 4.0.30319 SP1Rel, Windows 7 64-bit

Please provide any additional information below.
I've attached a related set of test cases for how I think list handling should 
be working. I'm not sure whether they're testing for the appropriate behavior 
or not, but they seem to be right going by the documentation on 
http://code.google.com/p/protobuf-net/wiki/Attributes .

Original issue reported on code.google.com by mdonou...@gmail.com on 19 Apr 2012 at 7:13

Attachments:

GoogleCodeExporter commented 9 years ago
I too have been having trouble with IgnoreListHandling today. Simple test 
example below:

namespace Tensys.Dev
{
    using System.Collections.Generic;
    using ProtoBuf;
    using System.Diagnostics;

    internal class Program
    {
        [ProtoContract]
        public class OuterList
        {
            [ProtoMember(1)]
            public readonly List<InnerList> regionData = new List<InnerList>();
        }

        [ProtoContract(IgnoreListHandling = true)]
        public class InnerList : IEnumerable<int>
        {
            [ProtoMember(1)]
            public readonly List<int> data = new List<int>();

            public IEnumerator<int> GetEnumerator()
            {
                return data.GetEnumerator();
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public bool Add(int item)
            {
                this.data.Add(item);
                return true;
            }
        }

        private static void Main(string[] args)
        {
            var outerList = new OuterList();
            var innerList = new InnerList();
            innerList.Add(1);
            innerList.Add(2);
            outerList.regionData.Add(innerList);

            var info = ProtoBuf.Meta.RuntimeTypeModel.Default[typeof(InnerList)];
            Debug.Assert(info.IgnoreListHandling == true); //OK

            var listClone = ProtoBuf.Serializer.DeepClone(innerList); //OK
            var testClone = ProtoBuf.Serializer.DeepClone(outerList); //Fails : Nested or jagged lists and arrays are not supported
        }
    }
}

Original comment by tom.ma...@gmail.com on 9 May 2013 at 4:02

GoogleCodeExporter commented 9 years ago
I've also had problems with the "Nested or jagged lists and arrays are not 
supported" exception being thrown by nested lists where the inner list has the 
IgnoreListHandling attribute. 

I've attached a fix to check for the attribute on inner lists before throwing 
the NotSupportedException.

Original comment by ppo4...@gmail.com on 6 Jun 2014 at 12:34

Attachments: