Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I Generate a .proto file from a C# class.
My C# class code contains more than 3000 lines of code .
.so wanted to see is there any easy way to do this ..convert C# (.cs) files to .proto file.

What I have tried:

Basically, given:

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;
}
I want to generate:

[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;
}
Posted
Updated 14-Apr-21 15:49pm

 
Share this answer
 
Comments
Member 12570593 7-Sep-16 8:34am    
.Proto is Protocol buffer file. I have C# module and would like to convert whole module to .proto file. and my C# module is huge file. so dont want to do it manually (convert to protocol definition.
3000 lines of code is too many, but that does not matter. Only the properties matter for protocol buffers. Converting that class to proto means only the properties will remain, no functions or fields will be there anymore, unless you create a surrogate DTO in the proto file and use a mapper to convert between the surrogate and the 3k class .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900