Skip to content

Allows the [Description] attribute annotation to be added to the code so that the annotation is carried when the proto file is generated #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

whuanle
Copy link

@whuanle whuanle commented Jul 12, 2024

Define model class:

[Description("BookDescription")]
[DataContract]
public class BookDescription
{
	[Description("ID")]
	[DataMember(Order = 1)]
	public int ID { get; set; }

	[Description("Title")]
	[DataMember(Order = 2)]
	public string Title { get; set; }

	[Description("Tags")]
	[DataMember(Order = 3)]
	public Dictionary<int, string> Tags { get; set; }

	[Description("PriceChanges")]
	[DataMember(Order = 4)]
	public int[] PriceChanges { get; set; }

	[Description("Type")]
	[DataMember(Order = 5)]
	public BookType Type { get; set; }
}

[Description("BookDescription")]
[DataContract]
public class BookTypeDescription
{
	[Description("Type")]
	[DataMember(Order = 1)]
	public BookType Type { get; set; }
}

[Description("BookType")]
[DataContract]
public enum BookType
{
	[DataMember(Order = 1)]
	[Description("Biology")]
	Biology,

	[DataMember(Order = 2)]
	[Description("Biology")]
	Chemistry
}

Generate the proto file:

syntax = ""proto3"";
package protobuf_net.Grpc.Reflection.Test;
import ""google/protobuf/empty.proto"";

// BookDescription
message BookDescription {
   // ID
   int32 ID = 1;
   // Title
   string Title = 2;
   map<int32,string> Tags = 3;
   // PriceChanges
   repeated int32 PriceChanges = 4 [packed = false];
   // Type
   BookType Type = 5;
}
// BookType
enum BookType {
   Biology = 0;
   Chemistry = 1;
}
// BookDescription
message BookTypeDescription {
   // Type
   BookType Type = 1;
}
// BookService
service BookService {
   // GetBookInfo
   rpc GetBookInfo (.google.protobuf.Empty) returns (BookDescription);
   // GetBookTypes
   rpc GetBookTypes (.google.protobuf.Empty) returns (BookTypeDescription);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant