From ca89a1a118c98d107421d40c4513e5aefdd2c3e3 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 25 Aug 2015 14:32:28 +0100 Subject: Change where we rename Descriptor.cs to DescriptorProtoFile.cs. We now do this in protoc instead of the generation simpler. Benefits: - Generation script is simpler - Detection is simpler as we now only need to care about one filename - The embedded descriptor knows itself as "google/protobuf/descriptor.proto" avoiding dependency issues This PR also makes the "invalid dependency" exception clearer in terms of expected and actual dependencies. --- src/google/protobuf/compiler/csharp/csharp_helpers.cc | 6 ++++++ src/google/protobuf/compiler/csharp/csharp_helpers.h | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/google') diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index d25dcba9..333b4912 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -118,6 +118,12 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) { } std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor) { + // We manually rename Descriptor to DescriptorProtoFile to avoid collisions with + // the static Descriptor property. It would be nice to be able to do this with an + // option, but it would be rarely used. + if (IsDescriptorProto(descriptor)) { + return "DescriptorProtoFile"; + } // umbrella_classname can no longer be set using message option. std::string proto_file = descriptor->name(); int lastslash = proto_file.find_last_of("/"); diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index 278e05f3..4ed17a84 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -115,12 +115,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { // for use in the runtime. This is the only type which is allowed to use proto2 syntax, // and it generates internal classes. inline bool IsDescriptorProto(const FileDescriptor* descriptor) { - // TODO: Do this better! (Currently this depends on a hack in generate_protos.sh to rename - // the file...) - // We need to be able to detect the "normal" name as well, for times that we're just - // depending on descriptor.proto instead of generating it. - return descriptor->name() == "google/protobuf/descriptor_proto_file.proto" - || descriptor->name() == "google/protobuf/descriptor.proto"; + return descriptor->name() == "google/protobuf/descriptor.proto"; } inline bool IsWrapperType(const FieldDescriptor* descriptor) { -- cgit v1.2.3