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;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos {
public enum EnumWithNoOuter {
......
......@@ -4,8 +4,6 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos {
public static partial class MultiFileProto {
......@@ -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,
0x6f, 0x74, 0x6f, 0xd0, 0x3e, 0x01, 0xd8, 0x3e, 0x00, 0xe0, 0x3e, 0x01,
}, new pbd::FileDescriptor[] {
self::UnitTestProtoFile.Descriptor,
global::Google.ProtocolBuffers.TestProtos.UnitTestProtoFile.Descriptor,
});
#endregion
......@@ -69,15 +67,15 @@ namespace Google.ProtocolBuffers.TestProtos {
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor,
new string[] { "Nested", "Foreign", "NestedEnum", "ForeignEnum", },
typeof (self::MessageWithNoOuter),
typeof (self::MessageWithNoOuter.Builder));
typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter),
typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Builder));
internal static readonly pbd::MessageDescriptor internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor
= internal__static_protobuf_unittest_MessageWithNoOuter__Descriptor.NestedTypes[0];
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_MessageWithNoOuter_NestedMessage__Descriptor,
new string[] { "I", },
typeof (self::MessageWithNoOuter.Types.NestedMessage),
typeof (self::MessageWithNoOuter.Types.NestedMessage.Builder));
typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Types.NestedMessage),
typeof (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.Types.NestedMessage.Builder));
#endregion
}
......
......@@ -4,18 +4,16 @@ using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos {
public abstract class ServiceWithNoOuter : pb::IService {
public abstract void Foo(
pb::IRpcController controller,
self::MessageWithNoOuter request,
global::System.Action<self::TestAllTypes> done);
global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter request,
global::System.Action<global::Google.ProtocolBuffers.TestProtos.TestAllTypes> done);
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 {
get { return Descriptor; }
......@@ -33,8 +31,8 @@ namespace Google.ProtocolBuffers.TestProtos {
}
switch(method.Index) {
case 0:
this.Foo(controller, (self::MessageWithNoOuter)request,
pb::RpcUtil.SpecializeCallback<self::TestAllTypes>(
this.Foo(controller, (global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter)request,
pb::RpcUtil.SpecializeCallback<global::Google.ProtocolBuffers.TestProtos.TestAllTypes>(
done));
return;
default:
......@@ -50,7 +48,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
switch(method.Index) {
case 0:
return self::MessageWithNoOuter.DefaultInstance;
return global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter.DefaultInstance;
default:
throw new global::System.ArgumentException("Can't get here.");
}
......@@ -64,7 +62,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
switch(method.Index) {
case 0:
return self::TestAllTypes.DefaultInstance;
return global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance;
default:
throw new global::System.ArgumentException("Can't get here.");
}
......@@ -75,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return new Stub(channel);
}
public class Stub : self::ServiceWithNoOuter {
public class Stub : global::Google.ProtocolBuffers.TestProtos.ServiceWithNoOuter {
internal Stub(pb::IRpcChannel channel) {
this.channel = channel;
}
......@@ -88,14 +86,14 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void Foo(
pb::IRpcController controller,
self::MessageWithNoOuter request,
global::System.Action<self::TestAllTypes> done) {
global::Google.ProtocolBuffers.TestProtos.MessageWithNoOuter request,
global::System.Action<global::Google.ProtocolBuffers.TestProtos.TestAllTypes> done) {
channel.CallMethod(
Descriptor.Methods[0],
controller,
request,
self::TestAllTypes.DefaultInstance,
pb::RpcUtil.GeneralizeCallback<self::TestAllTypes, self::TestAllTypes.Builder>(done, self::TestAllTypes.DefaultInstance));
global::Google.ProtocolBuffers.TestProtos.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;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
using self = global::Google.ProtocolBuffers.TestProtos;
namespace Google.ProtocolBuffers.TestProtos {
public static partial class UnitTestImportProtoFile {
......@@ -42,8 +40,8 @@ namespace Google.ProtocolBuffers.TestProtos {
internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_import_ImportMessage__FieldAccessorTable
= new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_import_ImportMessage__Descriptor,
new string[] { "D", },
typeof (self::ImportMessage),
typeof (self::ImportMessage.Builder));
typeof (global::Google.ProtocolBuffers.TestProtos.ImportMessage),
typeof (global::Google.ProtocolBuffers.TestProtos.ImportMessage.Builder));
#endregion
}
......@@ -69,11 +67,11 @@ namespace Google.ProtocolBuffers.TestProtos {
}
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 {
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;
......@@ -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();
}
public static self::ImportMessage ParseFrom(pb::ByteString data,
public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::ByteString data,
pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry))
.BuildParsed();
}
public static self::ImportMessage ParseFrom(byte[] data) {
public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(byte[] data) {
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) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry))
.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();
}
public static self::ImportMessage ParseFrom(
public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(
global::System.IO.Stream input,
pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry))
.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();
}
public static self::ImportMessage ParseFrom(pb::CodedInputStream input,
public static global::Google.ProtocolBuffers.TestProtos.ImportMessage ParseFrom(pb::CodedInputStream input,
pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry))
.BuildParsed();
......@@ -151,26 +149,26 @@ namespace Google.ProtocolBuffers.TestProtos {
public static Builder CreateBuilder() { 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);
}
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 {
get { return this; }
}
// Construct using self::ImportMessage.CreateBuilder()
// Construct using global::Google.ProtocolBuffers.TestProtos.ImportMessage.CreateBuilder()
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; }
}
public override Builder Clear() {
result = new self::ImportMessage();
result = new global::Google.ProtocolBuffers.TestProtos.ImportMessage();
return this;
}
......@@ -179,30 +177,30 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public override pbd::MessageDescriptor DescriptorForType {
get { return self::ImportMessage.Descriptor; }
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.Descriptor; }
}
public override self::ImportMessage DefaultInstanceForType {
get { return self::ImportMessage.DefaultInstance; }
public override global::Google.ProtocolBuffers.TestProtos.ImportMessage DefaultInstanceForType {
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance; }
}
public override self::ImportMessage BuildPartial() {
self::ImportMessage returnMe = result;
public override global::Google.ProtocolBuffers.TestProtos.ImportMessage BuildPartial() {
global::Google.ProtocolBuffers.TestProtos.ImportMessage returnMe = result;
result = null;
return returnMe;
}
public override Builder MergeFrom(pb::IMessage other) {
if (other is self::ImportMessage) {
return MergeFrom((self::ImportMessage) other);
if (other is global::Google.ProtocolBuffers.TestProtos.ImportMessage) {
return MergeFrom((global::Google.ProtocolBuffers.TestProtos.ImportMessage) other);
} else {
base.MergeFrom(other);
return this;
}
}
public override Builder MergeFrom(self::ImportMessage other) {
if (other == self::ImportMessage.DefaultInstance) return this;
public override Builder MergeFrom(global::Google.ProtocolBuffers.TestProtos.ImportMessage other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessage.DefaultInstance) return this;
if (other.HasD) {
D = other.D;
}
......
......@@ -95,8 +95,6 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Print("using scg = global::System.Collections.Generic;\r\n");
if (!csharp_namespace_.empty()) {
printer->Print("using self = global::$selfnamespace$;\r\n\r\n",
"selfnamespace", csharp_namespace_);
printer->Print(
"namespace $namespace$ {\r\n",
"namespace", csharp_namespace_);
......@@ -238,8 +236,6 @@ static void GenerateSibling(const string& csharp_namespace,
printer.Print("using scg = global::System.Collections.Generic;\r\n");
if (!csharp_namespace.empty()) {
printer.Print("using self = global::$selfnamespace$;\r\n\r\n",
"selfnamespace", csharp_namespace);
printer.Print(
"namespace $namespace$ {\r\n",
"namespace", csharp_namespace);
......
......@@ -138,7 +138,7 @@ string FileCSharpNamespace(const FileDescriptor* file) {
string ToCSharpName(const string& full_name, const FileDescriptor* file) {
string result;
if (!file->options().csharp_nest_classes()) {
result = "";
result = FileCSharpNamespace(file);
} else {
result = ClassName(file);
}
......@@ -150,17 +150,18 @@ string ToCSharpName(const string& full_name, const FileDescriptor* file) {
classname = full_name;
} else {
// 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);
}
result += StringReplace(classname, ".", ".Types.", true);
const char *prefix = FileCSharpNamespace(file).empty() ? "global::" : "self::";
return prefix + result;
return "global::" + result;
}
string ClassName(const FileDescriptor* descriptor) {
string alias = FileCSharpNamespace(descriptor).empty() ? "global::" : "self::";
return alias + FileClassName(descriptor);
string result = FileCSharpNamespace(descriptor);
if (!result.empty()) result += '.';
result += FileClassName(descriptor);
return "global::" + result;
}
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