aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs')
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs86
1 files changed, 21 insertions, 65 deletions
diff --git a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
index 7da14a54..9d0bdfd3 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
@@ -43,7 +43,7 @@ namespace Google.Protobuf.Descriptors
/// IDescriptor is implemented such that the File property returns this descriptor,
/// and the FullName is the same as the Name.
/// </summary>
- public sealed class FileDescriptor : IDescriptor<FileDescriptorProto>
+ public sealed class FileDescriptor : IDescriptor
{
private readonly FileDescriptorProto proto;
private readonly IList<MessageDescriptor> messageTypes;
@@ -88,6 +88,22 @@ namespace Google.Protobuf.Descriptors
}
/// <summary>
+ /// Computes the full name of a descriptor within this file, with an optional parent message.
+ /// </summary>
+ internal string ComputeFullName(MessageDescriptor parent, string name)
+ {
+ if (parent != null)
+ {
+ return parent.FullName + "." + name;
+ }
+ if (Package.Length > 0)
+ {
+ return Package + "." + name;
+ }
+ return name;
+ }
+
+ /// <summary>
/// Extracts public dependencies from direct dependencies. This is a static method despite its
/// first parameter, as the value we're in the middle of constructing is only used for exceptions.
/// </summary>
@@ -127,20 +143,12 @@ namespace Google.Protobuf.Descriptors
/// <value>
/// The descriptor in its protocol message representation.
/// </value>
- public FileDescriptorProto Proto
+ internal FileDescriptorProto Proto
{
get { return proto; }
}
/// <value>
- /// The <see cref="DescriptorProtos.FileOptions" /> defined in <c>descriptor.proto</c>.
- /// </value>
- public FileOptions Options
- {
- get { return proto.Options; }
- }
-
- /// <value>
/// The file name.
/// </value>
public string Name
@@ -214,14 +222,6 @@ namespace Google.Protobuf.Descriptors
}
/// <value>
- /// Protocol buffer describing this descriptor.
- /// </value>
- IMessage IDescriptor.Proto
- {
- get { return Proto; }
- }
-
- /// <value>
/// Pool containing symbol descriptors.
/// </value>
internal DescriptorPool DescriptorPool
@@ -255,22 +255,7 @@ namespace Google.Protobuf.Descriptors
}
return null;
}
-
- /// <summary>
- /// Builds a FileDescriptor from its protocol buffer representation.
- /// </summary>
- /// <param name="proto">The protocol message form of the FileDescriptor.</param>
- /// <param name="dependencies">FileDescriptors corresponding to all of the
- /// file's dependencies, in the exact order listed in the .proto file. May be null,
- /// in which case it is treated as an empty array.</param>
- /// <exception cref="DescriptorValidationException">If <paramref name="proto"/> is not
- /// a valid descriptor. This can occur for a number of reasons, such as a field
- /// having an undefined type or because two messages were defined with the same name.</exception>
- public static FileDescriptor BuildFrom(FileDescriptorProto proto, FileDescriptor[] dependencies)
- {
- return BuildFrom(proto, dependencies, false);
- }
-
+
/// <summary>
/// Builds a FileDescriptor from its protocol buffer representation.
/// </summary>
@@ -336,33 +321,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 +334,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()