diff options
author | Jon Skeet <jonskeet@google.com> | 2015-07-01 14:47:03 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-07-09 08:24:49 +0100 |
commit | 78ea98f56f7a0a028e378aee6394549707e199bc (patch) | |
tree | b3275e8d8b01528dc58af6ec0877c4ee79cd1b54 /csharp/src/ProtocolBuffers/Descriptors | |
parent | 3805b43009d35422bed85c56aaf2d6ce4d007fe5 (diff) | |
download | protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.tar.gz protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.tar.bz2 protobuf-78ea98f56f7a0a028e378aee6394549707e199bc.zip |
Implement reflection properly for fields.
- FieldAccessorTable is now non-generic
- We don't have a static field per message type in the umbrella class. (Message descriptors are accessed via the file descriptor.)
- Removed the "descriptor assigner" complication from the descriptor fixup; without extensions, we don't need it
- MapField implements IDictionary (more tests would be good...)
- RepeatedField implements IList (more tests would be good)
- Use expression trees to build accessors. (Will need to test this on various platforms... probably need a fallback strategy just using reflection directly.)
- Added FieldDescriptor.IsMap
- Added tests for reflection with generated messages
Changes to generated code coming in next commit.
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors')
-rw-r--r-- | csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs | 5 | ||||
-rw-r--r-- | csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs | 33 |
2 files changed, 7 insertions, 31 deletions
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs index 2f2c5806..3b36a280 100644 --- a/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs +++ b/csharp/src/ProtocolBuffers/Descriptors/FieldDescriptor.cs @@ -131,6 +131,11 @@ namespace Google.Protobuf.Descriptors get { return Proto.Label == FieldDescriptorProto.Types.Label.LABEL_REPEATED; }
}
+ public bool IsMap
+ {
+ get { return fieldType == FieldType.Message && messageType.Options != null && messageType.Options.MapEntry; }
+ }
+
public bool IsPacked
{
get { return Proto.Options.Packed; }
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs index 7da14a54..a6320a31 100644 --- a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs +++ b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs @@ -336,33 +336,8 @@ namespace Google.Protobuf.Descriptors }
}
- /// <summary>
- /// This method is to be called by generated code only. It is equivalent
- /// to BuildFrom except that the FileDescriptorProto is encoded in
- /// protocol buffer wire format. This overload is maintained for backward
- /// compatibility with source code generated before the custom options were available
- /// (and working).
- /// </summary>
- public static FileDescriptor InternalBuildGeneratedFileFrom(byte[] descriptorData, FileDescriptor[] dependencies)
- {
- return InternalBuildGeneratedFileFrom(descriptorData, dependencies, x => { });
- }
-
- /// <summary>
- /// This delegate should be used by generated code only. When calling
- /// FileDescriptor.InternalBuildGeneratedFileFrom, the caller can provide
- /// a callback which assigns the global variables defined in the generated code
- /// which point at parts of the FileDescriptor. The callback returns an
- /// Extension Registry which contains any extensions which might be used in
- /// the descriptor - that is, extensions of the various "Options" messages defined
- /// in descriptor.proto. The callback may also return null to indicate that
- /// no extensions are used in the descriptor.
- /// </summary>
- public delegate void InternalDescriptorAssigner(FileDescriptor descriptor);
-
public static FileDescriptor InternalBuildGeneratedFileFrom(byte[] descriptorData,
- FileDescriptor[] dependencies,
- InternalDescriptorAssigner descriptorAssigner)
+ FileDescriptor[] dependencies)
{
FileDescriptorProto proto;
try
@@ -374,20 +349,16 @@ namespace Google.Protobuf.Descriptors throw new ArgumentException("Failed to parse protocol buffer descriptor for generated code.", e);
}
- FileDescriptor result;
try
{
// When building descriptors for generated code, we allow unknown
// dependencies by default.
- result = BuildFrom(proto, dependencies, true);
+ return BuildFrom(proto, dependencies, true);
}
catch (DescriptorValidationException e)
{
throw new ArgumentException("Invalid embedded descriptor for \"" + proto.Name + "\".", e);
}
-
- descriptorAssigner(result);
- return result;
}
public override string ToString()
|