rongfengliang / protobuf-net

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

IgnoreListHandling is not used for members #312

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class with ProtoContract with a member whose type implements 
IEnumerable
2. Add IgnoreListHandling to the member type that implements IEnumerable
3. Serialize the top class

What is the expected output? What do you see instead?
Protobuf.net serialises the member class using default serialization instead of 
array/list serialization

What version of the product are you using? On what operating system?
2.0.0.480

Please provide any additional information below.
Can provide a reg test if necessary - my contact is erik@apption.com

Original issue reported on code.google.com by e...@apption.com on 8 Aug 2012 at 8:59

GoogleCodeExporter commented 9 years ago
Here is a test case

    [ProtoContract]
    public class RootClass
    {
        [ProtoMember(1)]
        public int Prop1 { get; set; }
        [ProtoMember(2)]
        public string Prop2 { get; set; }
        [ProtoMember(3)]
        public IEnumerableClass Prop3 { get; set; }
    }

    [ProtoContract(IgnoreListHandling=true)]
    public class IEnumerableClass :IEnumerable<char>
    {
        [ProtoMember(1)]
        public int Prop1 { get; set; }
        [ProtoMember(2)]
        public string Prop2 { get; set; }

        public IEnumerator<char> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        // Comment out this indexed property to prevent the crash
        public char this[int i] { get { return Prop2[i]; } }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }
    }

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var rt = TypeModel.Create();
            rt.Add(typeof(IEnumerableClass), true);
            rt.Add(typeof(RootClass), true);
            rt.Compile();
            var c1 = new IEnumerableClass() { Prop1 = 1, Prop2 = "a"};
            var i1 = new RootClass() { Prop1 = 1, Prop2 = "blabla", Prop3 =c1};
            var cloned = rt.DeepClone(i1) as RootClass;
            Assert.AreEqual(1, cloned.Prop3.Prop1);
        }
    }

Original comment by e...@apption.com on 9 Aug 2012 at 4:31

Attachments:

GoogleCodeExporter commented 9 years ago
This test passes when executed against the trunk (no new changes required).

Please retry on the current trunk, or r565 available at 
http://code.google.com/p/protobuf-net/downloads/list

Marc

Original comment by marc.gravell on 9 Aug 2012 at 7:28

GoogleCodeExporter commented 9 years ago
Any chances you could publish r565 on nuget?

Original comment by e...@apption.com on 9 Aug 2012 at 7:36

GoogleCodeExporter commented 9 years ago
Well, I'd rather not - but I guess I could publish it but leave r480 the 
default while I tie up something relating to `DynamicType`... would that 
suffice?

Original comment by marc.gravell on 9 Aug 2012 at 7:37

GoogleCodeExporter commented 9 years ago
that would be great! What about publishing r565 as prerelease? It seems as 
simple as adding a -rc at the end of the version number. 
http://docs.nuget.org/docs/Reference/Versioning

Original comment by e...@apption.com on 9 Aug 2012 at 7:58

GoogleCodeExporter commented 9 years ago
Er, yeah... see: 
http://stackoverflow.com/questions/11891401/is-pre-release-versioning-possible-i
n-nuget

Original comment by marc.gravell on 9 Aug 2012 at 8:28

GoogleCodeExporter commented 9 years ago
It is there now; it isn't default, so you'll need to use:

PM> Install-Package protobuf-net -Version 2.0.0.569

Original comment by marc.gravell on 9 Aug 2012 at 8:45