aboutsummaryrefslogtreecommitdiff
path: root/src/ProtoGen/DescriptorUtil.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2008-11-12 23:39:44 +0000
committerJon Skeet <skeet@pobox.com>2008-11-12 23:39:44 +0000
commitd6343be707cb6a067fe2b5ccc2efd7848072d17c (patch)
treeea4821795bcd032c0bc82461b699c5cef86c42ab /src/ProtoGen/DescriptorUtil.cs
parent60c059b8f0b2b01fba14c537e370b56445437510 (diff)
downloadprotobuf-d6343be707cb6a067fe2b5ccc2efd7848072d17c.tar.gz
protobuf-d6343be707cb6a067fe2b5ccc2efd7848072d17c.tar.bz2
protobuf-d6343be707cb6a067fe2b5ccc2efd7848072d17c.zip
Refactored options
Diffstat (limited to 'src/ProtoGen/DescriptorUtil.cs')
-rw-r--r--src/ProtoGen/DescriptorUtil.cs77
1 files changed, 4 insertions, 73 deletions
diff --git a/src/ProtoGen/DescriptorUtil.cs b/src/ProtoGen/DescriptorUtil.cs
index 72df575c..1d479bf0 100644
--- a/src/ProtoGen/DescriptorUtil.cs
+++ b/src/ProtoGen/DescriptorUtil.cs
@@ -10,80 +10,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
/// </summary>
internal static class DescriptorUtil {
- internal static bool NestClasses(IDescriptor descriptor) {
- // Defaults to false
- return descriptor.File.Options.GetExtension(CSharpOptions.CSharpNestClasses);
- }
-
- internal static string GetNamespace(FileDescriptor descriptor) {
- if (descriptor.Name == "google/protobuf/descriptor.proto") {
- return typeof(DescriptorProtoFile).Namespace;
- }
- return descriptor.Options.HasExtension(CSharpOptions.CSharpNamespace) ?
- descriptor.Options.GetExtension(CSharpOptions.CSharpNamespace) : descriptor.Package;
- }
-
- // Groups are hacky: The name of the field is just the lower-cased name
- // of the group type. In C#, though, we would like to retain the original
- // capitalization of the type name.
- internal static string GetFieldName(FieldDescriptor descriptor) {
- if (descriptor.FieldType == FieldType.Group) {
- return descriptor.MessageType.Name;
- } else {
- return descriptor.Name;
- }
- }
-
- internal static string GetClassName(IDescriptor descriptor) {
- return ToCSharpName(descriptor.FullName, descriptor.File);
- }
-
- internal static string GetFullUmbrellaClassName(FileDescriptor descriptor) {
- string result = GetNamespace(descriptor);
+ internal static string GetFullUmbrellaClassName(IDescriptor descriptor) {
+ CSharpFileOptions options = descriptor.File.CSharpOptions;
+ string result = options.Namespace;
if (result != "") result += '.';
- result += GetUmbrellaClassName(descriptor);
- return "global::" + result;
- }
-
- internal static string GetUmbrellaClassName(FileDescriptor descriptor) {
- if (descriptor.Name == "google/protobuf/descriptor.proto") {
- return typeof(DescriptorProtoFile).Name;
- }
- FileOptions options = descriptor.Options;
- if (options.HasExtension(CSharpOptions.CSharpUmbrellaClassname)) {
- return descriptor.Options.GetExtension(CSharpOptions.CSharpUmbrellaClassname);
- }
- int lastSlash = descriptor.Name.LastIndexOf('/');
- string baseName = descriptor.Name.Substring(lastSlash + 1);
- return Helpers.UnderscoresToPascalCase(StripProto(baseName));
- }
-
- private static string StripProto(string text) {
- if (!Helpers.StripSuffix(ref text, ".protodevel")) {
- Helpers.StripSuffix(ref text, ".proto");
- }
- return text;
- }
-
- private static string ToCSharpName(string name, FileDescriptor file) {
- string result;
- if (!NestClasses(file)) {
- result = GetNamespace(file);
- } else {
- result = GetUmbrellaClassName(file);
- }
- if (result != "") {
- result += '.';
- }
- string classname;
- if (file.Package == "") {
- classname = name;
- } else {
- // Strip the proto package from full_name since we've replaced it with
- // the C# namespace.
- classname = name.Substring(file.Package.Length + 1);
- }
- result += classname.Replace(".", ".Types.");
+ result += options.UmbrellaClassname;
return "global::" + result;
}