From 2a15051a1e101ea58d7d2e262aa79c7c21f23266 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 13 Nov 2015 20:04:03 +0000 Subject: Introduce a Parser property into MessageDescriptor, and populate it from generated types. Generated code coming in next commit - in a subsequent PR I want to do a bit of renaming and redocumenting around this, in anticipation of DynamicMessage. --- csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs | 10 ++++++++-- csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'csharp/src/Google.Protobuf/Reflection') diff --git a/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs b/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs index 8c52cd12..ff4ad0aa 100644 --- a/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs +++ b/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs @@ -17,6 +17,11 @@ namespace Google.Protobuf.Reflection /// public Type ClrType { get; private set; } + /// + /// Irrelevant for file descriptors; the parser for message descriptors. + /// + public MessageParser Parser { get; private set; } + /// /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order) /// for fields in the message for message descriptors. @@ -46,11 +51,12 @@ namespace Google.Protobuf.Reflection /// Each array parameter may be null, to indicate a lack of values. /// The parameter order is designed to make it feasible to format the generated code readably. /// - public GeneratedCodeInfo(Type clrType, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedCodeInfo[] nestedTypes) + public GeneratedCodeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedCodeInfo[] nestedTypes) { NestedTypes = nestedTypes ?? EmptyCodeInfo; NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; ClrType = clrType; + Parser = parser; PropertyNames = propertyNames ?? EmptyNames; OneofNames = oneofNames ?? EmptyNames; } @@ -59,7 +65,7 @@ namespace Google.Protobuf.Reflection /// Creates a GeneratedCodeInfo for a file descriptor, with only types and enums. /// public GeneratedCodeInfo(Type[] nestedEnums, GeneratedCodeInfo[] nestedTypes) - : this(null, null, null, nestedEnums, nestedTypes) + : this(null, null, null, null, nestedEnums, nestedTypes) { } } diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index e599998e..65040e42 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -67,11 +67,13 @@ namespace Google.Protobuf.Reflection private readonly IList oneofs; // CLR representation of the type described by this descriptor, if any. private readonly Type generatedType; + private readonly MessageParser parser; internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo) : base(file, file.ComputeFullName(parent, proto.Name), typeIndex) { this.proto = proto; + parser = generatedCodeInfo == null ? null : generatedCodeInfo.Parser; generatedType = generatedCodeInfo == null ? null : generatedCodeInfo.ClrType; containingType = parent; @@ -122,6 +124,15 @@ namespace Google.Protobuf.Reflection /// public Type GeneratedType { get { return generatedType; } } + /// + /// A parser for this message type. + /// + /// + /// As is not generic, this cannot be statically + /// typed to the relevant type, but if returns a non-null value, the parser returned + /// + public MessageParser Parser { get { return parser; } } + /// /// Returns whether this message is one of the "well known types" which may have runtime/protoc support. /// -- cgit v1.2.3