diff options
author | Jon Skeet <skeet@pobox.com> | 2015-07-14 09:50:57 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2015-07-14 09:50:57 +0100 |
commit | 9440a2abe3e3520fd6a1288f794f8bad0b26cb31 (patch) | |
tree | a74d26d051a53210682b76b0cc66b87eec3ecd65 /src | |
parent | b918dc1b17162465a1708cbf9f556b5a193196b2 (diff) | |
parent | 0f34daad07153a66b492ab938e85f17e82b91706 (diff) | |
download | protobuf-9440a2abe3e3520fd6a1288f794f8bad0b26cb31.tar.gz protobuf-9440a2abe3e3520fd6a1288f794f8bad0b26cb31.tar.bz2 protobuf-9440a2abe3e3520fd6a1288f794f8bad0b26cb31.zip |
Merge pull request #582 from jskeet/csharp-json
JSON formatting in C#
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_field_base.h | 1 | ||||
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_map_field.cc | 7 | ||||
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_message.cc | 6 |
3 files changed, 8 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 349d835b..bffa2062 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -58,6 +58,7 @@ class FieldGeneratorBase : public SourceGeneratorBase { virtual void WriteHash(io::Printer* printer) = 0; virtual void WriteEquals(io::Printer* printer) = 0; + // Currently unused, as we use reflection to generate JSON virtual void WriteToString(io::Printer* printer) = 0; protected: diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index cb7ce5f0..32c05232 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -117,12 +117,9 @@ void MapFieldGenerator::WriteEquals(io::Printer* printer) { variables_, "if (!$property_name$.Equals(other.$property_name$)) return false;\n"); } + void MapFieldGenerator::WriteToString(io::Printer* printer) { - /* - variables_["field_name"] = GetFieldName(descriptor_); - printer->Print( - variables_, - "PrintField(\"$field_name$\", has$property_name$, $name$_, writer);\n");*/ + // TODO: If we ever actually use ToString, we'll need to impleme this... } void MapFieldGenerator::GenerateCloningCode(io::Printer* printer) { diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 13544b26..3fbec2b5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -151,6 +151,7 @@ void MessageGenerator::GenerateStaticVariableInitializers(io::Printer* printer) printer->Print("\"$property_name$\", ", "property_name", GetPropertyName(descriptor_->field(i))); } + printer->Print("}, new string[] { "); for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { printer->Print("\"$oneof_name$\", ", "oneof_name", @@ -429,7 +430,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { printer->Outdent(); printer->Print("}\n\n"); - // TODO(jonskeet): ToString. + printer->Print( + "public override string ToString() {\n" + " return pb::JsonFormatter.Default.Format(this);\n" + "}\n\n"); } void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) { |