Commit eb4ef52c authored by Jon Skeet's avatar Jon Skeet

Abandon the 'self' namespace alias - we need to be able to import types in other namespaces too.

parent 5407a432
...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers; ...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections; using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors; using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic; using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos { namespace Google.ProtocolBuffers.TestProtos {
public enum EnumWithNoOuter { public enum EnumWithNoOuter {
......
...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers; ...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections; using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors; using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic; using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos { namespace Google.ProtocolBuffers.TestProtos {
public static partial class MultiFileProto { public static partial class MultiFileProto {
...@@ -54,7 +52,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -54,7 +52,7 @@ namespace Google.ProtocolBuffers.TestProtos {
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x3e, 0x0e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x46, 0x69, 0x6c, 0x65, 0x50, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0xca, 0x3e, 0x0e, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x46, 0x69, 0x6c, 0x65, 0x50, 0x72,
0x6f, 0x74, 0x6f, 0xd0, 0x3e, 0x01, 0xd8, 0x3e, 0x00, 0xe0, 0x3e, 0x01, 0x6f, 0x74, 0x6f, 0xd0, 0x3e, 0x01, 0xd8, 0x3e, 0x00, 0xe0, 0x3e, 0x01,
}, new pbd::FileDescriptor[] { }, new pbd::FileDescriptor[] {
self::UnitTestProtoFile.Descriptor, global::Google.ProtocolBuffers.TestProtos.UnitTestProtoFile.Descriptor,
}); });
#endregion #endregion
...@@ -69,15 +67,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -69,15 +67,15 @@ namespace Google.ProtocolBuffers.TestProtos {
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter__FieldAccessorTable internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor, = new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor,
new string[] { "Nested", "Foreign", "NestedEnum", "ForeignEnum", }, new string[] { "Nested", "Foreign", "NestedEnum", "ForeignEnum", },
typeof (self::MessageWithNoOuter), typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter),
typeof (self::MessageWithNoOuter.Builder)); typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Builder));
internal static readonly pbd::MessageDescriptor internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor internal static readonly pbd::MessageDescriptor internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor
= internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor.NestedTypes[0]; = internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor.NestedTypes[0];
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__FieldAccessorTable internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor, = new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor,
new string[] { "I", }, new string[] { "I", },
typeof (self::MessageWithNoOuter.Types.NestedMessage), typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Types.NestedMessage),
typeof (self::MessageWithNoOuter.Types.NestedMessage.Builder)); typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Types.NestedMessage.Builder));
#endregion #endregion
} }
......
...@@ -4,18 +4,16 @@ using pb = global::Google.ProtocolBuffers; ...@@ -4,18 +4,16 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections; using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors; using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic; using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos { namespace Google.ProtocolBuffers.TestProtos {
public abstract class ServiceWithNoOuter : pb::IService { public abstract class ServiceWithNoOuter : pb::IService {
public abstract void Foo( public abstract void Foo(
pb::IRpcController controller, pb::IRpcController controller,
self::MessageWithNoOuter request, global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter request,
global::System.Action<self::TestAllTypes> done); global::System.Action<global::Google.ProtocolBuffers.TestProtos.TestAllTypes> done);
public static pbd::ServiceDescriptor Descriptor { public static pbd::ServiceDescriptor Descriptor {
get { return self::MultiFileProto.Descriptor.Services[0]; } get { return global::Google.ProtocolBuffers.TestProtos.MultiFileProto.Descriptor.Services[0]; }
} }
public pbd::ServiceDescriptor DescriptorForType { public pbd::ServiceDescriptor DescriptorForType {
get { return Descriptor; } get { return Descriptor; }
...@@ -33,8 +31,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -33,8 +31,8 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
switch(method.Index) { switch(method.Index) {
case 0: case 0:
this.Foo(controller, (self::MessageWithNoOuter)request, this.Foo(controller, (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter)request,
pb::RpcUtil.SpecializeCallback<self::TestAllTypes>( pb::RpcUtil.SpecializeCallback<global::Google.ProtocolBuffers.TestProtos.TestAllTypes>(
done)); done));
return; return;
default: default:
...@@ -50,7 +48,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -50,7 +48,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
switch(method.Index) { switch(method.Index) {
case 0: case 0:
return self::MessageWithNoOuter.DefaultInstance; return global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.DefaultInstance;
default: default:
throw new global::System.ArgumentException("Can't get here."); throw new global::System.ArgumentException("Can't get here.");
} }
...@@ -64,7 +62,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -64,7 +62,7 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
switch(method.Index) { switch(method.Index) {
case 0: case 0:
return self::TestAllTypes.DefaultInstance; return global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance;
default: default:
throw new global::System.ArgumentException("Can't get here."); throw new global::System.ArgumentException("Can't get here.");
} }
...@@ -75,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -75,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return new Stub(channel); return new Stub(channel);
} }
public class Stub : self::ServiceWithNoOuter { public class Stub : global::Google.ProtocolBuffers.TestProtos.ServiceWithNoOuter {
internal Stub(pb::IRpcChannel channel) { internal Stub(pb::IRpcChannel channel) {
this.channel = channel; this.channel = channel;
} }
...@@ -88,14 +86,14 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -88,14 +86,14 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void Foo( public override void Foo(
pb::IRpcController controller, pb::IRpcController controller,
self::MessageWithNoOuter request, global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter request,
global::System.Action<self::TestAllTypes> done) { global::System.Action<global::Google.ProtocolBuffers.TestProtos.TestAllTypes> done) {
channel.CallMethod( channel.CallMethod(
Descriptor.Methods[0], Descriptor.Methods[0],
controller, controller,
request, request,
self::TestAllTypes.DefaultInstance, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance,
pb::RpcUtil.GeneralizeCallback<self::TestAllTypes, self::TestAllTypes.Builder>(done, self::TestAllTypes.DefaultInstance)); pb::RpcUtil.GeneralizeCallback<global::Google.ProtocolBuffers.TestProtos.TestAllTypes, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder>(done, global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance));
} }
} }
} }
......
...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers; ...@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections; using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors; using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic; using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos { namespace Google.ProtocolBuffers.TestProtos {
public static partial class UnitTestImportProtoFile { public static partial class UnitTestImportProtoFile {
...@@ -42,8 +40,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -42,8 +40,8 @@ namespace Google.ProtocolBuffers.TestProtos {
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_import_ImportMessage__Descriptor, = new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_import_ImportMessage__Descriptor,
new string[] { "D", }, new string[] { "D", },
typeof (self::ImportMessage), typeof (global::Google.ProtocolBuffers.TestProtos.ImportMessage),
typeof (self::ImportMessage.Builder)); typeof (global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder));
#endregion #endregion
} }
...@@ -69,11 +67,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -69,11 +67,11 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public static pbd::MessageDescriptor Descriptor { public static pbd::MessageDescriptor Descriptor {
get { return self::UnitTestImportProtoFile.internal__static_protobuf_unittest_import_ImportMessage__Descriptor; } get { return global::Google.ProtocolBuffers.TestProtos.UnitTestImportProtoFile.internal__static_protobuf_unittest_import_ImportMessage__Descriptor; }
} }
protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors {
get { return self::UnitTestImportProtoFile.internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable; } get { return global::Google.ProtocolBuffers.TestProtos.UnitTestImportProtoFile.internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable; }
} }
// optional int32 d = 1; // optional int32 d = 1;
...@@ -115,35 +113,35 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -115,35 +113,35 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
} }
public static self::ImportMessage ParseFrom(pb::ByteString data) { public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::ByteString data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
} }
public static self::ImportMessage ParseFrom(pb::ByteString data, public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::ByteString data,
pb::ExtensionRegistry extensionRegistry) { pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)) return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry))
.BuildParsed(); .BuildParsed();
} }
public static self::ImportMessage ParseFrom(byte[] data) { public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(byte[] data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
} }
public static self::ImportMessage ParseFrom(byte[] data, public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(byte[] data,
pb::ExtensionRegistry extensionRegistry) { pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)) return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry))
.BuildParsed(); .BuildParsed();
} }
public static self::ImportMessage ParseFrom(global::System.IO.Stream input) { public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(global::System.IO.Stream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
} }
public static self::ImportMessage ParseFrom( public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(
global::System.IO.Stream input, global::System.IO.Stream input,
pb::ExtensionRegistry extensionRegistry) { pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)) return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry))
.BuildParsed(); .BuildParsed();
} }
public static self::ImportMessage ParseFrom(pb::CodedInputStream input) { public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::CodedInputStream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
} }
public static self::ImportMessage ParseFrom(pb::CodedInputStream input, public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::CodedInputStream input,
pb::ExtensionRegistry extensionRegistry) { pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)) return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry))
.BuildParsed(); .BuildParsed();
...@@ -151,26 +149,26 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -151,26 +149,26 @@ namespace Google.ProtocolBuffers.TestProtos {
public static Builder CreateBuilder() { return new Builder(); } public static Builder CreateBuilder() { return new Builder(); }
public override Builder CreateBuilderForType() { return new Builder(); } public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(self::ImportMessage prototype) { public static Builder CreateBuilder(global::Google.ProtocolBuffers.TestProtos.ImportMessage prototype) {
return (Builder) new Builder().MergeFrom(prototype); return (Builder) new Builder().MergeFrom(prototype);
} }
public sealed partial class Builder : pb::GeneratedBuilder<self::ImportMessage, Builder> { public sealed partial class Builder : pb::GeneratedBuilder<global::Google.ProtocolBuffers.TestProtos.ImportMessage, Builder> {
protected override Builder ThisBuilder { protected override Builder ThisBuilder {
get { return this; } get { return this; }
} }
// Construct using self::ImportMessage.CreateBuilder() // Construct using global::Google.ProtocolBuffers.TestProtos.ImportMessage.CreateBuilder()
internal Builder() {} internal Builder() {}
self::ImportMessage result = new self::ImportMessage(); global::Google.ProtocolBuffers.TestProtos.ImportMessage result = new global::Google.ProtocolBuffers.TestProtos.ImportMessage();
protected override self::ImportMessage MessageBeingBuilt { protected override global::Google.ProtocolBuffers.TestProtos.ImportMessage MessageBeingBuilt {
get { return result; } get { return result; }
} }
public override Builder Clear() { public override Builder Clear() {
result = new self::ImportMessage(); result = new global::Google.ProtocolBuffers.TestProtos.ImportMessage();
return this; return this;
} }
...@@ -179,30 +177,30 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -179,30 +177,30 @@ namespace Google.ProtocolBuffers.TestProtos {
} }
public override pbd::MessageDescriptor DescriptorForType { public override pbd::MessageDescriptor DescriptorForType {
get { return self::ImportMessage.Descriptor; } get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.Descriptor; }
} }
public override self::ImportMessage DefaultInstanceForType { public override global::Google.ProtocolBuffers.TestProtos.ImportMessage DefaultInstanceForType {
get { return self::ImportMessage.DefaultInstance; } get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance; }
} }
public override self::ImportMessage BuildPartial() { public override global::Google.ProtocolBuffers.TestProtos.ImportMessage BuildPartial() {
self::ImportMessage returnMe = result; global::Google.ProtocolBuffers.TestProtos.ImportMessage returnMe = result;
result = null; result = null;
return returnMe; return returnMe;
} }
public override Builder MergeFrom(pb::IMessage other) { public override Builder MergeFrom(pb::IMessage other) {
if (other is self::ImportMessage) { if (other is global::Google.ProtocolBuffers.TestProtos.ImportMessage) {
return MergeFrom((self::ImportMessage) other); return MergeFrom((global::Google.ProtocolBuffers.TestProtos.ImportMessage) other);
} else { } else {
base.MergeFrom(other); base.MergeFrom(other);
return this; return this;
} }
} }
public override Builder MergeFrom(self::ImportMessage other) { public override Builder MergeFrom(global::Google.ProtocolBuffers.TestProtos.ImportMessage other) {
if (other == self::ImportMessage.DefaultInstance) return this; if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this;
if (other.HasD) { if (other.HasD) {
D = other.D; D = other.D;
} }
......
...@@ -95,8 +95,6 @@ void FileGenerator::Generate(io::Printer* printer) { ...@@ -95,8 +95,6 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Print("using scg = global::System.Collections.Generic;\r\n"); printer->Print("using scg = global::System.Collections.Generic;\r\n");
if (!csharp_namespace_.empty()) { if (!csharp_namespace_.empty()) {
printer->Print("using self = global::$selfnamespace$;\r\n\r\n",
"selfnamespace", csharp_namespace_);
printer->Print( printer->Print(
"namespace $namespace$ {\r\n", "namespace $namespace$ {\r\n",
"namespace", csharp_namespace_); "namespace", csharp_namespace_);
...@@ -238,8 +236,6 @@ static void GenerateSibling(const string& csharp_namespace, ...@@ -238,8 +236,6 @@ static void GenerateSibling(const string& csharp_namespace,
printer.Print("using scg = global::System.Collections.Generic;\r\n"); printer.Print("using scg = global::System.Collections.Generic;\r\n");
if (!csharp_namespace.empty()) { if (!csharp_namespace.empty()) {
printer.Print("using self = global::$selfnamespace$;\r\n\r\n",
"selfnamespace", csharp_namespace);
printer.Print( printer.Print(
"namespace $namespace$ {\r\n", "namespace $namespace$ {\r\n",
"namespace", csharp_namespace); "namespace", csharp_namespace);
......
...@@ -138,7 +138,7 @@ string FileCSharpNamespace(const FileDescriptor* file) { ...@@ -138,7 +138,7 @@ string FileCSharpNamespace(const FileDescriptor* file) {
string ToCSharpName(const string& full_name, const FileDescriptor* file) { string ToCSharpName(const string& full_name, const FileDescriptor* file) {
string result; string result;
if (!file->options().csharp_nest_classes()) { if (!file->options().csharp_nest_classes()) {
result = ""; result = FileCSharpNamespace(file);
} else { } else {
result = ClassName(file); result = ClassName(file);
} }
...@@ -150,17 +150,18 @@ string ToCSharpName(const string& full_name, const FileDescriptor* file) { ...@@ -150,17 +150,18 @@ string ToCSharpName(const string& full_name, const FileDescriptor* file) {
classname = full_name; classname = full_name;
} else { } else {
// Strip the proto package from full_name since we've replaced it with // Strip the proto package from full_name since we've replaced it with
// the C# package. // the C# namespace.
classname = full_name.substr(file->package().size() + 1); classname = full_name.substr(file->package().size() + 1);
} }
result += StringReplace(classname, ".", ".Types.", true); result += StringReplace(classname, ".", ".Types.", true);
const char *prefix = FileCSharpNamespace(file).empty() ? "global::" : "self::"; return "global::" + result;
return prefix + result;
} }
string ClassName(const FileDescriptor* descriptor) { string ClassName(const FileDescriptor* descriptor) {
string alias = FileCSharpNamespace(descriptor).empty() ? "global::" : "self::"; string result = FileCSharpNamespace(descriptor);
return alias + FileClassName(descriptor); if (!result.empty()) result += '.';
result += FileClassName(descriptor);
return "global::" + result;
} }
MappedType GetMappedType(FieldDescriptor::Type field_type) { MappedType GetMappedType(FieldDescriptor::Type field_type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment