aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-01 17:19:48 +0100
committerJon Skeet <jonskeet@google.com>2015-07-09 08:26:06 +0100
commitaf259b77bf04fcfb68609776cb27f04d289a2c39 (patch)
tree3e5434199a9c59b8556e9267fb9eb7b73211f8c5 /csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
parent5350822b0a923287bc23375a10c2f3cb07cff5fb (diff)
downloadprotobuf-af259b77bf04fcfb68609776cb27f04d289a2c39.tar.gz
protobuf-af259b77bf04fcfb68609776cb27f04d289a2c39.tar.bz2
protobuf-af259b77bf04fcfb68609776cb27f04d289a2c39.zip
Fix descriptor reflection in various ways
- The protos are no longer publicly exposed at all - Oneof detection now works (as we default to -1, not 0) - OneofDescriptor exposes the fields in the oneof - Removed unnecessary code for replacing protos - remnant of extensions - There's now just the non-generic form of IDescriptor
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs')
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs57
1 files changed, 14 insertions, 43 deletions
diff --git a/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
index cbf4c0f2..e65e8bb0 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/MessageDescriptor.cs
@@ -39,8 +39,9 @@ namespace Google.Protobuf.Descriptors
/// <summary>
/// Describes a message type.
/// </summary>
- public sealed class MessageDescriptor : IndexedDescriptorBase<DescriptorProto, MessageOptions>
+ public sealed class MessageDescriptor : DescriptorBase
{
+ private readonly DescriptorProto proto;
private readonly MessageDescriptor containingType;
private readonly IList<MessageDescriptor> nestedTypes;
private readonly IList<EnumDescriptor> enumTypes;
@@ -48,8 +49,9 @@ namespace Google.Protobuf.Descriptors
private readonly IList<OneofDescriptor> oneofs;
internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex)
- : base(proto, file, ComputeFullName(file, parent, proto.Name), typeIndex)
+ : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
{
+ this.proto = proto;
containingType = parent;
oneofs = DescriptorUtil.ConvertAndMakeReadOnly(proto.OneofDecl,
@@ -68,23 +70,16 @@ namespace Google.Protobuf.Descriptors
fields = DescriptorUtil.ConvertAndMakeReadOnly(proto.Field,
(field, index) =>
new FieldDescriptor(field, file, this, index));
-
- for (int i = 0; i < proto.OneofDecl.Count; i++)
- {
- oneofs[i].fields = new FieldDescriptor[oneofs[i].FieldCount];
- oneofs[i].fieldCount = 0;
- }
- for (int i = 0; i< proto.Field.Count; i++)
- {
- OneofDescriptor oneofDescriptor = fields[i].ContainingOneof;
- if (oneofDescriptor != null)
- {
- oneofDescriptor.fields[oneofDescriptor.fieldCount++] = fields[i];
- }
- }
file.DescriptorPool.AddSymbol(this);
}
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ internal DescriptorProto Proto { get { return proto; } }
+
/// <value>
/// If this is a nested type, get the outer descriptor, otherwise null.
/// </value>
@@ -144,7 +139,7 @@ namespace Google.Protobuf.Descriptors
/// <summary>
/// Finds a nested descriptor by name. The is valid for fields, nested
- /// message types and enums.
+ /// message types, oneofs and enums.
/// </summary>
/// <param name="name">The unqualified name of the descriptor, e.g. "Foo"</param>
/// <returns>The descriptor, or null if not found.</returns>
@@ -171,32 +166,8 @@ namespace Google.Protobuf.Descriptors
foreach (OneofDescriptor oneof in oneofs)
{
- // TODO(jonskeet): Do we need to do this?
- // oneof.C
- }
- }
-
- /// <summary>
- /// See FileDescriptor.ReplaceProto
- /// </summary>
- internal override void ReplaceProto(DescriptorProto newProto)
- {
- base.ReplaceProto(newProto);
-
- for (int i = 0; i < nestedTypes.Count; i++)
- {
- nestedTypes[i].ReplaceProto(newProto.NestedType[i]);
- }
-
- for (int i = 0; i < enumTypes.Count; i++)
- {
- enumTypes[i].ReplaceProto(newProto.EnumType[i]);
- }
-
- for (int i = 0; i < fields.Count; i++)
- {
- fields[i].ReplaceProto(newProto.Field[i]);
+ oneof.CrossLink();
}
- }
+ }
}
} \ No newline at end of file