code generation - Generate C# from proto files and vice versa interpreting custom options -


I am using, and I am trying:

  1. C # class Generate a .proto file from the C # class

    It is very easy to use this sequentially:

    1. Protogen.exe device
    2. the serializer & lt; T & gt; The GETProto () method

      But the thing is that I do not think it is as simple as supporting me as a proto buffer.

      Explain to me:

      1. From a custom option with a custom option applied to messages and fields, I want to generate a C # class decorated with .NET custom attributes.
      2. With a C # class decorated by custom attributes, I would like to generate a proto file where custom options apply to messages and fields. / Li>

        Actually, given:

          message person {option (my_message_option) = true; Alternate string first name = 1 [(my_field_option) = 42]; Alternate string last name = 2 [(my_field_option) = 12]; Optional int age = 3; }   

        I want to generate:

          [ProtoContract, MyMessageOption (true)] public class person {[ProtoMember (1), Myfield Operation (42 )] Public string firstname; [Proto member (2), myfield option (12)] public string firstname; [Proto member (3)] public string firstname; }   

        ... and vice versa.

        Note:

        • Custom options definitions ( my_message_option and my_field_option ) already exist in a profile ( Say, my_custom_options.proto), and custom feature classes can be found anywhere ( MyMessageOptionAttribute and MyFieldOptionAttribute ).
        • I tried using protogen.exe and a custom xslt but the proto is not supported for custom options.

          What is the preferred way to get that? Solution is not dependent on protobuf-net.

          i

          In this way, for proto gene project forking I was able to use the proto descriptor object model to write my own C # generator by generating some internal type (generator for the most part) and allowing custom generator registration SourceGenerators .

          Before launching parsing, register your custom option type:

          1. Generate the C # type for your custom options ( Protoc.exe using ProtoGen.exe )
          2. generated generated by using ExtensionRegistry register all extensions methods.
          3. Use your own C # generator to code generation. In each generator you can access the relevant descriptor.Options collection.

Comments