In fact, the current version supports comments. It can be enabled using --include_source_info.
Comments are available in the descriptor. Location [n] .leading_comments and trailing_comments: https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/descriptor.proto
I added the corresponding protobuf-net properties. Location Class:
private string _leading_comments = ""; [global::ProtoBuf.ProtoMember(3, IsRequired = false, Name = @"leading_comments", DataFormat = global::ProtoBuf.DataFormat.Default)] [global::System.ComponentModel.DefaultValue("")] public string leading_comments { get { return _leading_comments; } set { _leading_comments = value; } } private string _trailing_comments = ""; [global::ProtoBuf.ProtoMember(4, IsRequired = false, Name = @"trailing_comments", DataFormat = global::ProtoBuf.DataFormat.Default)] [global::System.ComponentModel.DefaultValue("")] public string trailing_comments { get { return _trailing_comments; } set { _trailing_comments = value; } }
And added --include_source_info to call the duct (ProtoBuf.CodeGenerator.InputFileLoader)
And places with comments were added to the generated XML:
<?xml version="1.0" encoding="utf-16"?> <FileDescriptorSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <file> <FileDescriptorProto> <name>Test.proto</name> <dependency /> <message_type> <DescriptorProto> <name>Test2</name> <field> <FieldDescriptorProto> <name>IntValue</name> <number>1</number> <type>TYPE_INT32</type> </FieldDescriptorProto> </field> <extension /> <nested_type /> <enum_type /> <extension_range /> </DescriptorProto> </message_type> <enum_type /> <service /> <extension /> <source_code_info> <location> ... <Location> <path> <int>4</int> <int>0</int> <int>2</int> <int>0</int> </path> <span> <int>1</int> <int>0</int> <int>28</int> </span> <trailing_comments> some comment </trailing_comments> </Location> ... </location> </source_code_info> </FileDescriptorProto> </file> </FileDescriptorSet>
source.proto:
message Test2{ optional int32 IntValue = 1;
But I am not good at xslt for updating ProtoGen / csharp.xslt for including comments in the generated CS file
source share