title: Generate C# from proto files and vice versa interpreting custom options
body: <p>I'm using <a href="http://code.google.com/p/protobuf-net/" rel="noreferrer">protobuf-net</a>, and I'm trying to:</p>
  
  <ol>
  <li>Generate a C# class from a .proto file </li>
  <li>Generate a .proto file from a C# class</li>
  </ol>
  
  <p>That's pretty easy using respectively:</p>
  
  <ol>
  <li><code>protogen.exe</code> tool</li>
  <li><code>Serializer&lt;T&gt;.GetProto()</code> method</li>
  </ol>
  
  <p>But the thing is that I need to support protobuffer <a href="http://code.google.com/apis/protocolbuffers/docs/proto.html#options" rel="noreferrer">custom options</a> and it doesn't seem to be as straightforward as I though.</p>
  
  <p>Let me explain:</p>
  
  <ol>
  <li>From a proto file containing custom options applied on messages and fields, I want to generate a C# class decorated by .NET custom attributes.</li>
  <li>From a C# class decorated by custom attributes, I would like to generate a proto file where custom options are applied on messages and fields.</li>
  </ol>
  
  <p>Basically, given:</p>
  
  <pre><code>message person {
     option (my_message_option) = true;
  
     optional string firstname = 1 [(my_field_option) = 42];
     optional string lastname = 2 [(my_field_option) = 12];
     optional int age = 3;
  }
  </code></pre>
  
  <p>I want to generate:</p>
  
  <pre><code>[ProtoContract, MyMessageOption(true)]
  public class Person
  {
      [ProtoMember(1), MyFieldOption(42)]
      public string Firstname;
  
      [ProtoMember(2), MyFieldOption(12)]
      public string Firstname;
  
      [ProtoMember(3)]
      public string Firstname;
  }
  </code></pre>
  
  <p>...and vice versa.</p>
  
  <p>Notes : </p>
  
  <ul>
  <li>The custom option definitions
  (<code>my_message_option</code> and
  <code>my_field_option</code>) can already exist
  in a protofile (say,
  my_custom_options.proto), and the
  custom attributes classes can also
  exist somewhere
  (<code>MyMessageOptionAttribute</code> and
  <code>MyFieldOptionAttribute</code>).</li>
  <li>I tried to use protogen.exe and a
  custom xslt but protogen doesn't seem
  to have support for custom options.</li>
  </ul>
  
  <p>What's the preferred way to achieve that? <strong>The solution doesn't have to rely on protobuf-net.</strong></p>