aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/csharp/csharp_generator.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_generator.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_generator.cc26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc
index 825de542..df9730f8 100644
--- a/src/google/protobuf/compiler/csharp/csharp_generator.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc
@@ -41,6 +41,7 @@
#include <google/protobuf/compiler/csharp/csharp_generator.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
#include <google/protobuf/compiler/csharp/csharp_names.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
#include <google/protobuf/compiler/csharp/csharp_reflection_class.h>
using google::protobuf::internal::scoped_ptr;
@@ -51,8 +52,9 @@ namespace compiler {
namespace csharp {
void GenerateFile(const google::protobuf::FileDescriptor* file,
- io::Printer* printer) {
- ReflectionClassGenerator reflectionClassGenerator(file);
+ io::Printer* printer,
+ const Options* options) {
+ ReflectionClassGenerator reflectionClassGenerator(file, options);
reflectionClassGenerator.Generate(printer);
}
@@ -71,15 +73,14 @@ bool Generator::Generate(
return false;
}
- std::string file_extension = ".cs";
- std::string base_namespace = "";
- bool generate_directories = false;
+ struct Options cli_options;
+
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "file_extension") {
- file_extension = options[i].second;
+ cli_options.file_extension = options[i].second;
} else if (options[i].first == "base_namespace") {
- base_namespace = options[i].second;
- generate_directories = true;
+ cli_options.base_namespace = options[i].second;
+ cli_options.base_namespace_specified = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
@@ -87,7 +88,12 @@ bool Generator::Generate(
}
string filename_error = "";
- std::string filename = GetOutputFile(file, file_extension, generate_directories, base_namespace, &filename_error);
+ std::string filename = GetOutputFile(file,
+ cli_options.file_extension,
+ cli_options.base_namespace_specified,
+ cli_options.base_namespace,
+ &filename_error);
+
if (filename.empty()) {
*error = filename_error;
return false;
@@ -96,7 +102,7 @@ bool Generator::Generate(
generator_context->Open(filename));
io::Printer printer(output.get(), '$');
- GenerateFile(file, &printer);
+ GenerateFile(file, &printer, &cli_options);
return true;
}