title: Protobuf Inheritance and Generics
body: <p>I am attempting to use ProtoBuf net to serialize an object tree with the classes in the following format:</p>
  
  <pre><code>[ProtoContract]
  class MySpecialCollectionList&lt;T&gt; : List&lt;MySpecialCollection&lt;T&gt;&gt;
  {
      [ProtoMember(1)]
      public string Name { get; set; }
  }
  
  [ProtoContract]
  class MySpecialCollection&lt;T&gt; : List&lt;Special&lt;T&gt;&gt;
  {
      [ProtoMember(1)]
      public string Name { get; set; }
  }
  
  [ProtoContract]
  class Special&lt;T&gt;
  {
      [ProtoMember(1)]
      public string Name { get; set; }
      [ProtoMember(2)]
      public string Description { get; set; }
  
      [ProtoMember(3)]
      private readonly T _source; 
      T Source { get { return _source; } }
  
      private Special()
      {
      }
  
      public Special(T source) 
      { 
          _source = source; 
      }
  }
  
  interface IBeast
  {
      string Name { get; set; }
  }
  [ProtoContract]
  class Ant : IBeast
  {
      [ProtoMember(1)]
      public string Name { get; set; }
  }
  [ProtoContract]
  class Cat : IBeast
  {
      [ProtoMember(1)]
      public string Name { get; set; }
  }
  [ProtoContract]
  class Dog : IBeast
  {
      [ProtoMember(1)]
      public string Name { get; set; }
  }
  
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          MySpecialCollectionList&lt;IBeast&gt; collectionList = GetSpecialCollectionList();
          using (var fs = File.Create(@"c:\temp\protobuftest.bin"))
          {
              Serializer.Serialize(fs, collectionList);
  
              fs.Close();
          }
      }
  
      private MySpecialCollectionList&lt;IBeast&gt; GetSpecialCollectionList()
      {
          var ant = new Ant() { Name = "Mr Ant" };
          var cat = new Cat() { Name = "Mr Cat" };
          var dog = new Dog() { Name = "Mr Dog" };
  
          var Special = new Special&lt;IBeast&gt;(ant);
  
          var specialCollection1 = new MySpecialCollection&lt;IBeast&gt;() {
              {new Special&lt;IBeast&gt;(ant)},
              {new Special&lt;IBeast&gt;(cat)},
              {new Special&lt;IBeast&gt;(dog)}
          };
          specialCollection1.Name = "Special Collection1";
  
  
          var specialCollection2 = new MySpecialCollection&lt;IBeast&gt;() {
              {new Special&lt;IBeast&gt;(ant)},
              {new Special&lt;IBeast&gt;(dog)}
          };
          specialCollection2.Name = "Special Collection2";
  
          var specialCollectionList = new MySpecialCollectionList&lt;IBeast&gt;() {
              specialCollection1, specialCollection2 };
  
          specialCollectionList.Name = "Special Collection List";
          return specialCollectionList;
      }
  }
  </code></pre>
  
  <p>Notice how the class I am serializing (<code>MySpecialCollectionList&lt;T&gt;</code>) is derived from a <code>List&lt;SomeOtherClass&lt;T&gt;&gt;</code>, not just <code>List&lt;T&gt;</code>.</p>
  
  <p>I am struggling to work out where to put "ProtoInclude" attributes to get this to serialize all the items in the MySpecialCollectionList.  Any help would be much appreciated.</p>