Add C# plugin "file_suffix" option defaulting to "Grpc.cs" (#26162)

* add C# plugin "file_extension" option defaulting to "Grpc.cs"

* rename to "file_suffix" to avoid confusion

* address review feedback
pull/26233/head
Jan Tattermusch 4 years ago committed by GitHub
parent 60c74c29f5
commit 98ccb7fd94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/compiler/csharp_generator_helpers.h
  2. 9
      src/compiler/csharp_plugin.cc

@ -25,9 +25,10 @@
namespace grpc_csharp_generator {
inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
std::string* file_name_or_error) {
*file_name_or_error =
grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs";
const std::string& file_suffix,
std::string& out_file_name_or_error) {
out_file_name_or_error =
grpc_generator::FileNameInUpperCamel(file, false) + file_suffix;
return true;
}

@ -43,6 +43,9 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
bool generate_client = true;
bool generate_server = true;
bool internal_access = false;
// the suffix that will get appended to the name generated from the name
// of the original .proto file
std::string file_suffix = "Grpc.cs";
for (size_t i = 0; i < options.size(); i++) {
if (options[i].first == "no_client") {
generate_client = false;
@ -50,6 +53,9 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
generate_server = false;
} else if (options[i].first == "internal_access") {
internal_access = true;
}
if (options[i].first == "file_suffix") {
file_suffix = options[i].second;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
@ -64,7 +70,8 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
// Get output file name.
std::string file_name;
if (!grpc_csharp_generator::ServicesFilename(file, &file_name)) {
if (!grpc_csharp_generator::ServicesFilename(file, file_suffix,
file_name)) {
return false;
}
std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output(

Loading…
Cancel
Save