title: Protobuf-net : Nested IEnumerable objects
body: <p>I am using Protobuf-net to serialize a custom nested list. I understand that native lists cannot be nested directly, which is why I have used a container object for the inner list. However, I would also like to make my container objects IEnumerable but this means Protobuf-net throws it out with the error:</p>
  
  <blockquote>
    <p>Nested or jagged lists and arrays are not supported</p>
  </blockquote>
  
  <p>Here is an example of my list structure which causes the error:</p>
  
  <pre><code>[ProtoContract]
  public class MyOuterList&lt;T&gt;
  {
      [ProtoMember(1)]
      readonly List&lt;MyInnerList&lt;T&gt;&gt; nestedData = new List&lt;ObjectList&lt;T&gt;&gt;();
  }
  
  [ProtoContract]
  public class MyInnerList&lt;T&gt; : IEnumerable&lt;T&gt;
  {
      [ProtoMember(1)]
      private readonly List&lt;T&gt; data = new List&lt;T&gt;();
  }
  </code></pre>
  
  <p>The fix is to remove IEnumerable from <code>MyInnerList</code> but obviously that prevents it being directly iterable. Is there a sneaky attribute like <code>[ProtobufCustomObjectSoPleaseIgnoreIEnumerable]</code> that could be used? </p>
  
  <p>The best alternative I have come up with so far is to use an Enumerable property as shown below but I fear that the property could still be cast back to a list again. I would prefer to be using <code>GetEnumerator/yield</code> in some way but I can't see how.</p>
  
  <pre><code>[ProtoContract]
  public class MyInnerList&lt;T&gt;
  {
      [ProtoMember(1)]
      private readonly List&lt;T&gt; data = new List&lt;T&gt;();
  
      public IEnumerable&lt;T&gt; Data
      {
          get { return this.data; }
      }
  }
  </code></pre>