I am using, and I am trying:
- C # class Generate a .proto file from the C # class
It is very easy to use this sequentially:
-
Protogen.exe devicethe serializer & lt; T & gt; The GETProto () methodBut the thing is that I do not think it is as simple as supporting me as a proto buffer.
Explain to me:
- 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.
- 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 andmy_field_option ) already exist in a profile ( Say, my_custom_options.proto), and custom feature classes can be found anywhere (MyMessageOptionAttribute andMyFieldOptionAttribute ).- 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:
- Generate the C # type for your custom options (
Protoc.exe usingProtoGen.exe )- generated
generated by usingExtensionRegistry register all extensions methods.- Use your own C # generator to code generation. In each generator you can access the relevant
descriptor.Options collection.
- generated
- I tried using protogen.exe and a custom xslt but the proto is not supported for custom options.
- Custom options definitions (
-
Comments
Post a Comment