diff options
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_generator.cc')
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_generator.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc index e0a6c83a..f5ff880f 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -36,10 +36,12 @@ #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> +#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/compiler/csharp/csharp_generator.h> -#include <google/protobuf/compiler/csharp/csharp_umbrella_class.h> #include <google/protobuf/compiler/csharp/csharp_helpers.h> +#include <google/protobuf/compiler/csharp/csharp_names.h> +#include <google/protobuf/compiler/csharp/csharp_umbrella_class.h> using google::protobuf::internal::scoped_ptr; @@ -48,11 +50,6 @@ namespace protobuf { namespace compiler { namespace csharp { -std::string GetOutputFile(const google::protobuf::FileDescriptor* file, const std::string file_extension) -{ - return GetUmbrellaClassUnqualifiedName(file) + file_extension; -} - void GenerateFile(const google::protobuf::FileDescriptor* file, io::Printer* printer) { UmbrellaClassGenerator umbrellaGenerator(file); @@ -75,16 +72,26 @@ bool Generator::Generate( } std::string file_extension = ".cs"; + std::string base_namespace = ""; + bool generate_directories = false; for (int i = 0; i < options.size(); i++) { if (options[i].first == "file_extension") { file_extension = options[i].second; + } else if (options[i].first == "base_namespace") { + base_namespace = options[i].second; + generate_directories = true; } else { *error = "Unknown generator option: " + options[i].first; return false; } } - std::string filename = GetOutputFile(file, file_extension); + string filename_error = ""; + std::string filename = GetOutputFile(file, file_extension, generate_directories, base_namespace, &filename_error); + if (filename.empty()) { + *error = filename_error; + return false; + } scoped_ptr<io::ZeroCopyOutputStream> output( generator_context->Open(filename)); io::Printer printer(output.get(), '$'); |