瀏覽代碼

Merge pull request #1349 from gvaish/master

Added CLI option internal_access for types (C#)
Jon Skeet 9 年之前
父節點
當前提交
89719f07a3
共有 32 個文件被更改,包括 177 次插入84 次删除
  1. 1 0
      cmake/extract_includes.bat.in
  2. 1 0
      src/Makefile.am
  3. 2 2
      src/google/protobuf/compiler/csharp/csharp_enum.cc
  4. 1 1
      src/google/protobuf/compiler/csharp/csharp_enum.h
  5. 5 4
      src/google/protobuf/compiler/csharp/csharp_enum_field.cc
  6. 2 2
      src/google/protobuf/compiler/csharp/csharp_enum_field.h
  7. 2 2
      src/google/protobuf/compiler/csharp/csharp_field_base.cc
  8. 1 1
      src/google/protobuf/compiler/csharp/csharp_field_base.h
  9. 16 10
      src/google/protobuf/compiler/csharp/csharp_generator.cc
  10. 14 13
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  11. 2 1
      src/google/protobuf/compiler/csharp/csharp_helpers.h
  12. 5 4
      src/google/protobuf/compiler/csharp/csharp_map_field.cc
  13. 1 1
      src/google/protobuf/compiler/csharp/csharp_map_field.h
  14. 5 5
      src/google/protobuf/compiler/csharp/csharp_message.cc
  15. 1 1
      src/google/protobuf/compiler/csharp/csharp_message.h
  16. 5 4
      src/google/protobuf/compiler/csharp/csharp_message_field.cc
  17. 2 2
      src/google/protobuf/compiler/csharp/csharp_message_field.h
  18. 60 0
      src/google/protobuf/compiler/csharp/csharp_options.h
  19. 5 4
      src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
  20. 4 2
      src/google/protobuf/compiler/csharp/csharp_primitive_field.h
  21. 6 4
      src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
  22. 1 1
      src/google/protobuf/compiler/csharp/csharp_reflection_class.h
  23. 2 2
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
  24. 1 1
      src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
  25. 4 4
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
  26. 3 1
      src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
  27. 2 2
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
  28. 1 1
      src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
  29. 8 2
      src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
  30. 5 1
      src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
  31. 5 4
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
  32. 4 2
      src/google/protobuf/compiler/csharp/csharp_wrapper_field.h

+ 1 - 0
cmake/extract_includes.bat.in

@@ -23,6 +23,7 @@ copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h include\google\protobuf\compiler\cpp\cpp_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h include\google\protobuf\compiler\cpp\cpp_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h include\google\protobuf\compiler\csharp\csharp_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h include\google\protobuf\compiler\csharp\csharp_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h include\google\protobuf\compiler\csharp\csharp_names.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h include\google\protobuf\compiler\csharp\csharp_names.h
+copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_options.h include\google\protobuf\compiler\csharp\csharp_options.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h include\google\protobuf\compiler\importer.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h include\google\protobuf\compiler\importer.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h include\google\protobuf\compiler\java\java_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h include\google\protobuf\compiler\java\java_generator.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_names.h include\google\protobuf\compiler\java\java_names.h
 copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_names.h include\google\protobuf\compiler\java\java_names.h

+ 1 - 0
src/Makefile.am

@@ -455,6 +455,7 @@ libprotoc_la_SOURCES =                                         \
   google/protobuf/compiler/csharp/csharp_message.h             \
   google/protobuf/compiler/csharp/csharp_message.h             \
   google/protobuf/compiler/csharp/csharp_message_field.cc      \
   google/protobuf/compiler/csharp/csharp_message_field.cc      \
   google/protobuf/compiler/csharp/csharp_message_field.h       \
   google/protobuf/compiler/csharp/csharp_message_field.h       \
+  google/protobuf/compiler/csharp/csharp_options.h             \
   google/protobuf/compiler/csharp/csharp_primitive_field.cc    \
   google/protobuf/compiler/csharp/csharp_primitive_field.cc    \
   google/protobuf/compiler/csharp/csharp_primitive_field.h     \
   google/protobuf/compiler/csharp/csharp_primitive_field.h     \
   google/protobuf/compiler/csharp/csharp_reflection_class.cc     \
   google/protobuf/compiler/csharp/csharp_reflection_class.cc     \

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_enum.cc

@@ -49,8 +49,8 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
-EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) :
-    SourceGeneratorBase(descriptor->file()),
+EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, const Options* options) :
+    SourceGeneratorBase(descriptor->file(), options),
     descriptor_(descriptor) {
     descriptor_(descriptor) {
 }
 }
 
 

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_enum.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class EnumGenerator : public SourceGeneratorBase {
 class EnumGenerator : public SourceGeneratorBase {
  public:
  public:
-  EnumGenerator(const EnumDescriptor* descriptor);
+  EnumGenerator(const EnumDescriptor* descriptor, const Options* options);
   ~EnumGenerator();
   ~EnumGenerator();
 
 
   void Generate(io::Printer* printer);
   void Generate(io::Printer* printer);

+ 5 - 4
src/google/protobuf/compiler/csharp/csharp_enum_field.cc

@@ -38,6 +38,7 @@
 #include <google/protobuf/io/zero_copy_stream.h>
 #include <google/protobuf/io/zero_copy_stream.h>
 
 
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
 #include <google/protobuf/compiler/csharp/csharp_enum_field.h>
 #include <google/protobuf/compiler/csharp/csharp_enum_field.h>
 
 
 namespace google {
 namespace google {
@@ -46,8 +47,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor,
 EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor,
-                                       int fieldOrdinal)
-    : PrimitiveFieldGenerator(descriptor, fieldOrdinal) {
+                                       int fieldOrdinal, const Options *options)
+    : PrimitiveFieldGenerator(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 EnumFieldGenerator::~EnumFieldGenerator() {
 EnumFieldGenerator::~EnumFieldGenerator() {
@@ -81,8 +82,8 @@ void EnumFieldGenerator::GenerateCodecCode(io::Printer* printer) {
 }
 }
 
 
 EnumOneofFieldGenerator::EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
 EnumOneofFieldGenerator::EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
-						 int fieldOrdinal)
-  : PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal) {
+						 int fieldOrdinal, const Options *options)
+  : PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {
 EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_enum_field.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class EnumFieldGenerator : public PrimitiveFieldGenerator {
 class EnumFieldGenerator : public PrimitiveFieldGenerator {
  public:
  public:
-  EnumFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  EnumFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~EnumFieldGenerator();
   ~EnumFieldGenerator();
 
 
   virtual void GenerateCodecCode(io::Printer* printer);
   virtual void GenerateCodecCode(io::Printer* printer);
@@ -57,7 +57,7 @@ class EnumFieldGenerator : public PrimitiveFieldGenerator {
 
 
 class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
 class EnumOneofFieldGenerator : public PrimitiveOneofFieldGenerator {
  public:
  public:
-  EnumOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  EnumOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~EnumOneofFieldGenerator();
   ~EnumOneofFieldGenerator();
 
 
   virtual void GenerateParsingCode(io::Printer* printer);
   virtual void GenerateParsingCode(io::Printer* printer);

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_field_base.cc

@@ -100,8 +100,8 @@ void FieldGeneratorBase::SetCommonOneofFieldVariables(
 }
 }
 
 
 FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor,
 FieldGeneratorBase::FieldGeneratorBase(const FieldDescriptor* descriptor,
-                                       int fieldOrdinal)
-    : SourceGeneratorBase(descriptor->file()),
+                                       int fieldOrdinal, const Options* options)
+    : SourceGeneratorBase(descriptor->file(), options),
       descriptor_(descriptor),
       descriptor_(descriptor),
       fieldOrdinal_(fieldOrdinal) {
       fieldOrdinal_(fieldOrdinal) {
   SetCommonFieldVariables(&variables_);
   SetCommonFieldVariables(&variables_);

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_field_base.h

@@ -44,7 +44,7 @@ namespace csharp {
 
 
 class FieldGeneratorBase : public SourceGeneratorBase {
 class FieldGeneratorBase : public SourceGeneratorBase {
  public:
  public:
-  FieldGeneratorBase(const FieldDescriptor* descriptor, int fieldOrdinal);
+  FieldGeneratorBase(const FieldDescriptor* descriptor, int fieldOrdinal, const Options* options);
   ~FieldGeneratorBase();
   ~FieldGeneratorBase();
 
 
   virtual void GenerateCloningCode(io::Printer* printer) = 0;
   virtual void GenerateCloningCode(io::Printer* printer) = 0;

+ 16 - 10
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_generator.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_names.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>
 #include <google/protobuf/compiler/csharp/csharp_reflection_class.h>
 
 
 using google::protobuf::internal::scoped_ptr;
 using google::protobuf::internal::scoped_ptr;
@@ -51,8 +52,9 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 void GenerateFile(const google::protobuf::FileDescriptor* file,
 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);
   reflectionClassGenerator.Generate(printer);
 }
 }
 
 
@@ -71,15 +73,14 @@ bool Generator::Generate(
     return false;
     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++) {
   for (int i = 0; i < options.size(); i++) {
     if (options[i].first == "file_extension") {
     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") {
     } else if (options[i].first == "base_namespace") {
-      base_namespace = options[i].second;
-      generate_directories = true;
+      cli_options.base_namespace = options[i].second;
+      cli_options.generate_directories = true;
     } else {
     } else {
       *error = "Unknown generator option: " + options[i].first;
       *error = "Unknown generator option: " + options[i].first;
       return false;
       return false;
@@ -87,7 +88,12 @@ bool Generator::Generate(
   }
   }
 
 
   string filename_error = "";
   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.generate_directories,
+      cli_options.base_namespace,
+      &filename_error);
+
   if (filename.empty()) {
   if (filename.empty()) {
     *error = filename_error;
     *error = filename_error;
     return false;
     return false;
@@ -96,7 +102,7 @@ bool Generator::Generate(
       generator_context->Open(filename));
       generator_context->Open(filename));
   io::Printer printer(output.get(), '$');
   io::Printer printer(output.get(), '$');
 
 
-  GenerateFile(file, &printer);
+  GenerateFile(file, &printer, &cli_options);
 
 
   return true;
   return true;
 }
 }

+ 14 - 13
src/google/protobuf/compiler/csharp/csharp_helpers.cc

@@ -48,6 +48,7 @@
 #include <google/protobuf/compiler/csharp/csharp_enum_field.h>
 #include <google/protobuf/compiler/csharp/csharp_enum_field.h>
 #include <google/protobuf/compiler/csharp/csharp_map_field.h>
 #include <google/protobuf/compiler/csharp/csharp_map_field.h>
 #include <google/protobuf/compiler/csharp/csharp_message_field.h>
 #include <google/protobuf/compiler/csharp/csharp_message_field.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
 #include <google/protobuf/compiler/csharp/csharp_primitive_field.h>
 #include <google/protobuf/compiler/csharp/csharp_primitive_field.h>
 #include <google/protobuf/compiler/csharp/csharp_repeated_enum_field.h>
 #include <google/protobuf/compiler/csharp/csharp_repeated_enum_field.h>
 #include <google/protobuf/compiler/csharp/csharp_repeated_message_field.h>
 #include <google/protobuf/compiler/csharp/csharp_repeated_message_field.h>
@@ -351,49 +352,49 @@ std::string FileDescriptorToBase64(const FileDescriptor* descriptor) {
 }
 }
 
 
 FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor,
 FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor,
-                                         int fieldOrdinal) {
+                                         int fieldOrdinal, const Options* options) {
   switch (descriptor->type()) {
   switch (descriptor->type()) {
     case FieldDescriptor::TYPE_GROUP:
     case FieldDescriptor::TYPE_GROUP:
     case FieldDescriptor::TYPE_MESSAGE:
     case FieldDescriptor::TYPE_MESSAGE:
       if (descriptor->is_repeated()) {
       if (descriptor->is_repeated()) {
         if (descriptor->is_map()) {
         if (descriptor->is_map()) {
-          return new MapFieldGenerator(descriptor, fieldOrdinal);
+          return new MapFieldGenerator(descriptor, fieldOrdinal, options);
         } else {
         } else {
-          return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal);
+          return new RepeatedMessageFieldGenerator(descriptor, fieldOrdinal, options);
         }
         }
       } else {
       } else {
         if (IsWrapperType(descriptor)) {
         if (IsWrapperType(descriptor)) {
           if (descriptor->containing_oneof()) {
           if (descriptor->containing_oneof()) {
-            return new WrapperOneofFieldGenerator(descriptor, fieldOrdinal);
+            return new WrapperOneofFieldGenerator(descriptor, fieldOrdinal, options);
           } else {
           } else {
-            return new WrapperFieldGenerator(descriptor, fieldOrdinal);
+            return new WrapperFieldGenerator(descriptor, fieldOrdinal, options);
           }
           }
         } else {
         } else {
           if (descriptor->containing_oneof()) {
           if (descriptor->containing_oneof()) {
-            return new MessageOneofFieldGenerator(descriptor, fieldOrdinal);
+            return new MessageOneofFieldGenerator(descriptor, fieldOrdinal, options);
           } else {
           } else {
-            return new MessageFieldGenerator(descriptor, fieldOrdinal);
+            return new MessageFieldGenerator(descriptor, fieldOrdinal, options);
           }
           }
         }
         }
       }
       }
     case FieldDescriptor::TYPE_ENUM:
     case FieldDescriptor::TYPE_ENUM:
       if (descriptor->is_repeated()) {
       if (descriptor->is_repeated()) {
-        return new RepeatedEnumFieldGenerator(descriptor, fieldOrdinal);
+        return new RepeatedEnumFieldGenerator(descriptor, fieldOrdinal, options);
       } else {
       } else {
         if (descriptor->containing_oneof()) {
         if (descriptor->containing_oneof()) {
-          return new EnumOneofFieldGenerator(descriptor, fieldOrdinal);
+          return new EnumOneofFieldGenerator(descriptor, fieldOrdinal, options);
         } else {
         } else {
-          return new EnumFieldGenerator(descriptor, fieldOrdinal);
+          return new EnumFieldGenerator(descriptor, fieldOrdinal, options);
         }
         }
       }
       }
     default:
     default:
       if (descriptor->is_repeated()) {
       if (descriptor->is_repeated()) {
-        return new RepeatedPrimitiveFieldGenerator(descriptor, fieldOrdinal);
+        return new RepeatedPrimitiveFieldGenerator(descriptor, fieldOrdinal, options);
       } else {
       } else {
         if (descriptor->containing_oneof()) {
         if (descriptor->containing_oneof()) {
-          return new PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal);
+          return new PrimitiveOneofFieldGenerator(descriptor, fieldOrdinal, options);
         } else {
         } else {
-          return new PrimitiveFieldGenerator(descriptor, fieldOrdinal);
+          return new PrimitiveFieldGenerator(descriptor, fieldOrdinal, options);
         }
         }
       }
       }
   }
   }

+ 2 - 1
src/google/protobuf/compiler/csharp/csharp_helpers.h

@@ -46,6 +46,7 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
+struct Options;
 class FieldGeneratorBase;
 class FieldGeneratorBase;
 
 
 // TODO: start using this enum.
 // TODO: start using this enum.
@@ -95,7 +96,7 @@ std::string StringToBase64(const std::string& input);
 
 
 std::string FileDescriptorToBase64(const FileDescriptor* descriptor);
 std::string FileDescriptorToBase64(const FileDescriptor* descriptor);
 
 
-FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+FieldGeneratorBase* CreateFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options* options);
 
 
 // Determines whether the given message is a map entry message, i.e. one implicitly created
 // Determines whether the given message is a map entry message, i.e. one implicitly created
 // by protoc due to a map<key, value> field.
 // by protoc due to a map<key, value> field.

+ 5 - 4
src/google/protobuf/compiler/csharp/csharp_map_field.cc

@@ -48,8 +48,9 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
 MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
-                                             int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+                                     int fieldOrdinal,
+                                     const Options* options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 MapFieldGenerator::~MapFieldGenerator() {
 MapFieldGenerator::~MapFieldGenerator() {
@@ -62,8 +63,8 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) {
       descriptor_->message_type()->FindFieldByName("value");
       descriptor_->message_type()->FindFieldByName("value");
   variables_["key_type_name"] = type_name(key_descriptor);
   variables_["key_type_name"] = type_name(key_descriptor);
   variables_["value_type_name"] = type_name(value_descriptor);
   variables_["value_type_name"] = type_name(value_descriptor);
-  scoped_ptr<FieldGeneratorBase> key_generator(CreateFieldGenerator(key_descriptor, 1));  
-  scoped_ptr<FieldGeneratorBase> value_generator(CreateFieldGenerator(value_descriptor, 2));
+  scoped_ptr<FieldGeneratorBase> key_generator(CreateFieldGenerator(key_descriptor, 1, this->options()));
+  scoped_ptr<FieldGeneratorBase> value_generator(CreateFieldGenerator(value_descriptor, 2, this->options()));
 
 
   printer->Print(
   printer->Print(
     variables_,
     variables_,

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_map_field.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class MapFieldGenerator : public FieldGeneratorBase {
 class MapFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  MapFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  MapFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options* options);
   ~MapFieldGenerator();
   ~MapFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 5 - 5
src/google/protobuf/compiler/csharp/csharp_message.cc

@@ -60,8 +60,8 @@ bool CompareFieldNumbers(const FieldDescriptor* d1, const FieldDescriptor* d2) {
   return d1->number() < d2->number();
   return d1->number() < d2->number();
 }
 }
 
 
-MessageGenerator::MessageGenerator(const Descriptor* descriptor)
-    : SourceGeneratorBase(descriptor->file()),
+MessageGenerator::MessageGenerator(const Descriptor* descriptor, const Options* options)
+    : SourceGeneratorBase(descriptor->file(), options),
       descriptor_(descriptor) {
       descriptor_(descriptor) {
 
 
   // sorted field names
   // sorted field names
@@ -214,13 +214,13 @@ void MessageGenerator::Generate(io::Printer* printer) {
     printer->Print("public static partial class Types {\n");
     printer->Print("public static partial class Types {\n");
     printer->Indent();
     printer->Indent();
     for (int i = 0; i < descriptor_->enum_type_count(); i++) {
     for (int i = 0; i < descriptor_->enum_type_count(); i++) {
-      EnumGenerator enumGenerator(descriptor_->enum_type(i));
+      EnumGenerator enumGenerator(descriptor_->enum_type(i), this->options());
       enumGenerator.Generate(printer);
       enumGenerator.Generate(printer);
     }
     }
     for (int i = 0; i < descriptor_->nested_type_count(); i++) {
     for (int i = 0; i < descriptor_->nested_type_count(); i++) {
       // Don't generate nested types for maps...
       // Don't generate nested types for maps...
       if (!IsMapEntryMessage(descriptor_->nested_type(i))) {
       if (!IsMapEntryMessage(descriptor_->nested_type(i))) {
-        MessageGenerator messageGenerator(descriptor_->nested_type(i));
+        MessageGenerator messageGenerator(descriptor_->nested_type(i), this->options());
         messageGenerator.Generate(printer);
         messageGenerator.Generate(printer);
       }
       }
     }
     }
@@ -490,7 +490,7 @@ int MessageGenerator::GetFieldOrdinal(const FieldDescriptor* descriptor) {
 
 
 FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal(
 FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal(
     const FieldDescriptor* descriptor) {
     const FieldDescriptor* descriptor) {
-  return CreateFieldGenerator(descriptor, GetFieldOrdinal(descriptor));
+  return CreateFieldGenerator(descriptor, GetFieldOrdinal(descriptor), this->options());
 }
 }
 
 
 }  // namespace csharp
 }  // namespace csharp

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_message.h

@@ -47,7 +47,7 @@ class FieldGeneratorBase;
 
 
 class MessageGenerator : public SourceGeneratorBase {
 class MessageGenerator : public SourceGeneratorBase {
  public:
  public:
-  MessageGenerator(const Descriptor* descriptor);
+  MessageGenerator(const Descriptor* descriptor, const Options* options);
   ~MessageGenerator();
   ~MessageGenerator();
 
 
   void GenerateCloningCode(io::Printer* printer);
   void GenerateCloningCode(io::Printer* printer);

+ 5 - 4
src/google/protobuf/compiler/csharp/csharp_message_field.cc

@@ -41,6 +41,7 @@
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_message_field.h>
 #include <google/protobuf/compiler/csharp/csharp_message_field.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
 
 
 namespace google {
 namespace google {
 namespace protobuf {
 namespace protobuf {
@@ -48,8 +49,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor,
 MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor,
-                                             int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+                                             int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
   variables_["has_property_check"] = name() + "_ != null";
   variables_["has_property_check"] = name() + "_ != null";
   variables_["has_not_property_check"] = name() + "_ == null";
   variables_["has_not_property_check"] = name() + "_ == null";
 }
 }
@@ -144,8 +145,8 @@ void MessageFieldGenerator::GenerateCodecCode(io::Printer* printer) {
 }
 }
 
 
 MessageOneofFieldGenerator::MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
 MessageOneofFieldGenerator::MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
-						       int fieldOrdinal)
-    : MessageFieldGenerator(descriptor, fieldOrdinal) {
+						       int fieldOrdinal, const Options *options)
+    : MessageFieldGenerator(descriptor, fieldOrdinal, options) {
   SetCommonOneofFieldVariables(&variables_);
   SetCommonOneofFieldVariables(&variables_);
 }
 }
 
 

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_message_field.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class MessageFieldGenerator : public FieldGeneratorBase {
 class MessageFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  MessageFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  MessageFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~MessageFieldGenerator();
   ~MessageFieldGenerator();
 
 
   virtual void GenerateCodecCode(io::Printer* printer);
   virtual void GenerateCodecCode(io::Printer* printer);
@@ -65,7 +65,7 @@ class MessageFieldGenerator : public FieldGeneratorBase {
 
 
 class MessageOneofFieldGenerator : public MessageFieldGenerator {
 class MessageOneofFieldGenerator : public MessageFieldGenerator {
  public:
  public:
-  MessageOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  MessageOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~MessageOneofFieldGenerator();
   ~MessageOneofFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 60 - 0
src/google/protobuf/compiler/csharp/csharp_options.h

@@ -0,0 +1,60 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.  All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//     * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__
+#define GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__
+
+#include <string>
+
+#include <google/protobuf/stubs/common.h>
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace csharp {
+
+// Generator options (used by csharp_generator.cc):
+struct Options {
+  Options() : file_extension(".cs"), base_namespace(""), generate_directories(false) {
+  }
+  // Extension of the generated file. Defaults to ".cs"
+  string file_extension;
+  // Base namespace to use to create directory hierarchy. Defaults to ""
+  string base_namespace;
+  // Whether or not to generate directory hierarchy. Defaults to false
+  bool generate_directories;
+};
+
+}  // namespace csharp
+}  // namespace compiler
+}  // namespace protobuf
+
+
+}  // namespace google
+#endif  // GOOGLE_PROTOBUF_COMPILER_CSHARP_OPTIONS_H__

+ 5 - 4
src/google/protobuf/compiler/csharp/csharp_primitive_field.cc

@@ -40,6 +40,7 @@
 
 
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
 #include <google/protobuf/compiler/csharp/csharp_primitive_field.h>
 #include <google/protobuf/compiler/csharp/csharp_primitive_field.h>
 
 
 namespace google {
 namespace google {
@@ -48,8 +49,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 PrimitiveFieldGenerator::PrimitiveFieldGenerator(
 PrimitiveFieldGenerator::PrimitiveFieldGenerator(
-    const FieldDescriptor* descriptor, int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+    const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
   // TODO(jonskeet): Make this cleaner...
   // TODO(jonskeet): Make this cleaner...
   is_value_type = descriptor->type() != FieldDescriptor::TYPE_STRING
   is_value_type = descriptor->type() != FieldDescriptor::TYPE_STRING
       && descriptor->type() != FieldDescriptor::TYPE_BYTES;
       && descriptor->type() != FieldDescriptor::TYPE_BYTES;
@@ -163,8 +164,8 @@ void PrimitiveFieldGenerator::GenerateCodecCode(io::Printer* printer) {
 }
 }
 
 
 PrimitiveOneofFieldGenerator::PrimitiveOneofFieldGenerator(
 PrimitiveOneofFieldGenerator::PrimitiveOneofFieldGenerator(
-    const FieldDescriptor* descriptor, int fieldOrdinal)
-    : PrimitiveFieldGenerator(descriptor, fieldOrdinal) {
+    const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options)
+    : PrimitiveFieldGenerator(descriptor, fieldOrdinal, options) {
   SetCommonOneofFieldVariables(&variables_);
   SetCommonOneofFieldVariables(&variables_);
 }
 }
 
 

+ 4 - 2
src/google/protobuf/compiler/csharp/csharp_primitive_field.h

@@ -41,9 +41,11 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
+struct Options;
+
 class PrimitiveFieldGenerator : public FieldGeneratorBase {
 class PrimitiveFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  PrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  PrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~PrimitiveFieldGenerator();
   ~PrimitiveFieldGenerator();
 
 
   virtual void GenerateCodecCode(io::Printer* printer);
   virtual void GenerateCodecCode(io::Printer* printer);
@@ -67,7 +69,7 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase {
 
 
 class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
 class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
  public:
  public:
-  PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~PrimitiveOneofFieldGenerator();
   ~PrimitiveOneofFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 6 - 4
src/google/protobuf/compiler/csharp/csharp_reflection_class.cc

@@ -43,6 +43,7 @@
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_message.h>
 #include <google/protobuf/compiler/csharp/csharp_message.h>
 #include <google/protobuf/compiler/csharp/csharp_names.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>
 #include <google/protobuf/compiler/csharp/csharp_reflection_class.h>
 
 
 namespace google {
 namespace google {
@@ -50,8 +51,9 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
-ReflectionClassGenerator::ReflectionClassGenerator(const FileDescriptor* file)
-    : SourceGeneratorBase(file),
+ReflectionClassGenerator::ReflectionClassGenerator(const FileDescriptor* file,
+                                                   const Options* options)
+    : SourceGeneratorBase(file, options),
       file_(file) {
       file_(file) {
   namespace_ = GetFileNamespace(file);
   namespace_ = GetFileNamespace(file);
   reflectionClassname_ = GetReflectionClassUnqualifiedName(file);
   reflectionClassname_ = GetReflectionClassUnqualifiedName(file);
@@ -72,7 +74,7 @@ void ReflectionClassGenerator::Generate(io::Printer* printer) {
   if (file_->enum_type_count() > 0) {
   if (file_->enum_type_count() > 0) {
     printer->Print("#region Enums\n");
     printer->Print("#region Enums\n");
     for (int i = 0; i < file_->enum_type_count(); i++) {
     for (int i = 0; i < file_->enum_type_count(); i++) {
-      EnumGenerator enumGenerator(file_->enum_type(i));
+      EnumGenerator enumGenerator(file_->enum_type(i), this->options());
       enumGenerator.Generate(printer);
       enumGenerator.Generate(printer);
     }
     }
     printer->Print("#endregion\n");
     printer->Print("#endregion\n");
@@ -83,7 +85,7 @@ void ReflectionClassGenerator::Generate(io::Printer* printer) {
   if (file_->message_type_count() > 0) {
   if (file_->message_type_count() > 0) {
     printer->Print("#region Messages\n");
     printer->Print("#region Messages\n");
     for (int i = 0; i < file_->message_type_count(); i++) {
     for (int i = 0; i < file_->message_type_count(); i++) {
-      MessageGenerator messageGenerator(file_->message_type(i));
+      MessageGenerator messageGenerator(file_->message_type(i), this->options());
       messageGenerator.Generate(printer);
       messageGenerator.Generate(printer);
     }
     }
     printer->Print("#endregion\n");
     printer->Print("#endregion\n");

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_reflection_class.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class ReflectionClassGenerator : public SourceGeneratorBase {
 class ReflectionClassGenerator : public SourceGeneratorBase {
  public:
  public:
-  ReflectionClassGenerator(const FileDescriptor* file);
+  ReflectionClassGenerator(const FileDescriptor* file, const Options* options);
   ~ReflectionClassGenerator();
   ~ReflectionClassGenerator();
 
 
   void Generate(io::Printer* printer);
   void Generate(io::Printer* printer);

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc

@@ -48,8 +48,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
 RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
-    const FieldDescriptor* descriptor, int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+    const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {
 RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h

@@ -45,7 +45,7 @@ namespace csharp {
 // should probably have a RepeatedFieldGeneratorBase.
 // should probably have a RepeatedFieldGeneratorBase.
 class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
 class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~RepeatedEnumFieldGenerator();
   ~RepeatedEnumFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 4 - 4
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc

@@ -49,8 +49,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator(
 RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator(
-    const FieldDescriptor* descriptor, int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+    const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {
 RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {
@@ -66,10 +66,10 @@ void RepeatedMessageFieldGenerator::GenerateMembers(io::Printer* printer) {
   // "create single field generator for this repeated field"
   // "create single field generator for this repeated field"
   // function, but it doesn't seem worth it for just this.
   // function, but it doesn't seem worth it for just this.
   if (IsWrapperType(descriptor_)) {
   if (IsWrapperType(descriptor_)) {
-    scoped_ptr<FieldGeneratorBase> single_generator(new WrapperFieldGenerator(descriptor_, fieldOrdinal_));
+    scoped_ptr<FieldGeneratorBase> single_generator(new WrapperFieldGenerator(descriptor_, fieldOrdinal_, this->options()));
     single_generator->GenerateCodecCode(printer);
     single_generator->GenerateCodecCode(printer);
   } else {
   } else {
-    scoped_ptr<FieldGeneratorBase> single_generator(new MessageFieldGenerator(descriptor_, fieldOrdinal_));
+    scoped_ptr<FieldGeneratorBase> single_generator(new MessageFieldGenerator(descriptor_, fieldOrdinal_, this->options()));
     single_generator->GenerateCodecCode(printer);
     single_generator->GenerateCodecCode(printer);
   }
   }
   printer->Print(";\n");
   printer->Print(";\n");

+ 3 - 1
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h

@@ -41,9 +41,11 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
+struct Options;
+
 class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
 class RepeatedMessageFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~RepeatedMessageFieldGenerator();
   ~RepeatedMessageFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 2 - 2
src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc

@@ -48,8 +48,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
 RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
-    const FieldDescriptor* descriptor, int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+    const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
 }
 }
 
 
 RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {
 RepeatedPrimitiveFieldGenerator::~RepeatedPrimitiveFieldGenerator() {

+ 1 - 1
src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h

@@ -43,7 +43,7 @@ namespace csharp {
 
 
 class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
 class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~RepeatedPrimitiveFieldGenerator();
   ~RepeatedPrimitiveFieldGenerator();
 
 
   virtual void GenerateCloningCode(io::Printer* printer);
   virtual void GenerateCloningCode(io::Printer* printer);

+ 8 - 2
src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc

@@ -39,14 +39,16 @@
 
 
 #include <google/protobuf/compiler/csharp/csharp_source_generator_base.h>
 #include <google/protobuf/compiler/csharp/csharp_source_generator_base.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.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>
 
 
 namespace google {
 namespace google {
 namespace protobuf {
 namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
-SourceGeneratorBase::SourceGeneratorBase(const FileDescriptor* descriptor)
-    : descriptor_(descriptor) {
+SourceGeneratorBase::SourceGeneratorBase(const FileDescriptor* descriptor, const Options *options)
+    : descriptor_(descriptor), options_(options) {
 }
 }
 
 
 SourceGeneratorBase::~SourceGeneratorBase() {
 SourceGeneratorBase::~SourceGeneratorBase() {
@@ -60,6 +62,10 @@ std::string SourceGeneratorBase::class_access_level() {
   return IsDescriptorProto(descriptor_) ? "internal" : "public";  // public_classes is always on.
   return IsDescriptorProto(descriptor_) ? "internal" : "public";  // public_classes is always on.
 }
 }
 
 
+const Options* SourceGeneratorBase::options() {
+  return this->options_;
+}
+
 }  // namespace csharp
 }  // namespace csharp
 }  // namespace compiler
 }  // namespace compiler
 }  // namespace protobuf
 }  // namespace protobuf

+ 5 - 1
src/google/protobuf/compiler/csharp/csharp_source_generator_base.h

@@ -40,17 +40,21 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
+struct Options;
+
 class SourceGeneratorBase {
 class SourceGeneratorBase {
  protected:
  protected:
-  SourceGeneratorBase(const FileDescriptor* descriptor);
+  SourceGeneratorBase(const FileDescriptor* descriptor, const Options* options);
   virtual ~SourceGeneratorBase();
   virtual ~SourceGeneratorBase();
 
 
   std::string class_access_level();
   std::string class_access_level();
+  const Options* options();
 
 
   void WriteGeneratedCodeAttributes(io::Printer* printer);
   void WriteGeneratedCodeAttributes(io::Printer* printer);
 
 
  private:
  private:
   const FileDescriptor* descriptor_;
   const FileDescriptor* descriptor_;
+  const Options *options_;
 
 
   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceGeneratorBase);
   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceGeneratorBase);
 };
 };

+ 5 - 4
src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc

@@ -39,6 +39,7 @@
 
 
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_doc_comment.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
 #include <google/protobuf/compiler/csharp/csharp_helpers.h>
+#include <google/protobuf/compiler/csharp/csharp_options.h>
 #include <google/protobuf/compiler/csharp/csharp_wrapper_field.h>
 #include <google/protobuf/compiler/csharp/csharp_wrapper_field.h>
 
 
 namespace google {
 namespace google {
@@ -47,8 +48,8 @@ namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
 WrapperFieldGenerator::WrapperFieldGenerator(const FieldDescriptor* descriptor,
 WrapperFieldGenerator::WrapperFieldGenerator(const FieldDescriptor* descriptor,
-                                       int fieldOrdinal)
-    : FieldGeneratorBase(descriptor, fieldOrdinal) {
+                                       int fieldOrdinal, const Options *options)
+    : FieldGeneratorBase(descriptor, fieldOrdinal, options) {
   variables_["has_property_check"] = name() + "_ != null";
   variables_["has_property_check"] = name() + "_ != null";
   variables_["has_not_property_check"] = name() + "_ == null";
   variables_["has_not_property_check"] = name() + "_ == null";
   const FieldDescriptor* wrapped_field = descriptor->message_type()->field(0);
   const FieldDescriptor* wrapped_field = descriptor->message_type()->field(0);
@@ -152,8 +153,8 @@ void WrapperFieldGenerator::GenerateCodecCode(io::Printer* printer) {
 }
 }
 
 
 WrapperOneofFieldGenerator::WrapperOneofFieldGenerator(const FieldDescriptor* descriptor,
 WrapperOneofFieldGenerator::WrapperOneofFieldGenerator(const FieldDescriptor* descriptor,
-    int fieldOrdinal)
-    : WrapperFieldGenerator(descriptor, fieldOrdinal) {
+    int fieldOrdinal, const Options *options)
+    : WrapperFieldGenerator(descriptor, fieldOrdinal, options) {
     SetCommonOneofFieldVariables(&variables_);
     SetCommonOneofFieldVariables(&variables_);
 }
 }
 
 

+ 4 - 2
src/google/protobuf/compiler/csharp/csharp_wrapper_field.h

@@ -41,9 +41,11 @@ namespace protobuf {
 namespace compiler {
 namespace compiler {
 namespace csharp {
 namespace csharp {
 
 
+struct Options;
+
 class WrapperFieldGenerator : public FieldGeneratorBase {
 class WrapperFieldGenerator : public FieldGeneratorBase {
  public:
  public:
-  WrapperFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  WrapperFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~WrapperFieldGenerator();
   ~WrapperFieldGenerator();
 
 
   virtual void GenerateCodecCode(io::Printer* printer);
   virtual void GenerateCodecCode(io::Printer* printer);
@@ -65,7 +67,7 @@ class WrapperFieldGenerator : public FieldGeneratorBase {
 
 
 class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
 class WrapperOneofFieldGenerator : public WrapperFieldGenerator {
  public:
  public:
-  WrapperOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal);
+  WrapperOneofFieldGenerator(const FieldDescriptor* descriptor, int fieldOrdinal, const Options *options);
   ~WrapperOneofFieldGenerator();
   ~WrapperOneofFieldGenerator();
 
 
   virtual void GenerateMembers(io::Printer* printer);
   virtual void GenerateMembers(io::Printer* printer);