aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-07-22 11:38:22 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2015-07-22 11:38:22 +0100
commit4668c3dc3921e157b7904e26a1ddd84287b881be (patch)
tree755b120ba988871c074454bc6b2a829d86fdd1e7 /csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
parent8d115298c7fc6fec135515ff7ddacb7f1524149e (diff)
Remove the usage of attributes for field/method discovery.
Instead, introduce GeneratedCodeInfo which passes in what we need, and adjust the codegen to take account of this.
Diffstat (limited to 'csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs')
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs42
1 files changed, 23 insertions, 19 deletions
diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
index 9413cf61..b29b4b20 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -66,29 +66,33 @@ namespace Google.Protobuf.Reflection
private readonly Type generatedType;
private IDictionary<int, IFieldAccessor> fieldAccessorsByFieldNumber;
- internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, IEnumerator<Type> generatedTypeIterator)
+ internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo)
: base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
{
this.proto = proto;
- generatedType = ReflectionUtil.GetNextType(generatedTypeIterator);
- containingType = parent;
-
- oneofs = DescriptorUtil.ConvertAndMakeReadOnly(proto.OneofDecl,
- (oneof, index) =>
- new OneofDescriptor(oneof, file, this, index));
-
- nestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.NestedType,
- (type, index) =>
- new MessageDescriptor(type, file, this, index, generatedTypeIterator));
+ generatedType = generatedCodeInfo == null ? null : generatedCodeInfo.ClrType;
- enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType,
- (type, index) =>
- new EnumDescriptor(type, file, this, index, ReflectionUtil.GetNextType(generatedTypeIterator)));
+ containingType = parent;
- // TODO(jonskeet): Sort fields first?
- fields = DescriptorUtil.ConvertAndMakeReadOnly(proto.Field,
- (field, index) =>
- new FieldDescriptor(field, file, this, index));
+ oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.OneofDecl,
+ (oneof, index) =>
+ new OneofDescriptor(oneof, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.OneofNames[index]));
+
+ nestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.NestedType,
+ (type, index) =>
+ new MessageDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedTypes[index]));
+
+ enumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.EnumType,
+ (type, index) =>
+ new EnumDescriptor(type, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.NestedEnums[index]));
+
+ fields = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.Field,
+ (field, index) =>
+ new FieldDescriptor(field, file, this, index, generatedCodeInfo == null ? null : generatedCodeInfo.PropertyNames[index]));
file.DescriptorPool.AddSymbol(this);
}
@@ -220,6 +224,6 @@ namespace Google.Protobuf.Reflection
}
fieldAccessorsByFieldNumber = new ReadOnlyDictionary<int, IFieldAccessor>(fields.ToDictionary(field => field.FieldNumber, field => field.Accessor));
- }
+ }
}
} \ No newline at end of file