aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs')
-rw-r--r--csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs63
1 files changed, 15 insertions, 48 deletions
diff --git a/csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs b/csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs
index ccde34ab..0eb71215 100644
--- a/csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs
+++ b/csharp/src/ProtocolBuffers/Descriptors/DescriptorBase.cs
@@ -34,61 +34,36 @@ using Google.Protobuf.DescriptorProtos;
namespace Google.Protobuf.Descriptors
{
- // TODO(jonskeet): The descriptor type hierarchy needs changing so that we can hide the descriptor protos.
/// <summary>
/// Base class for nearly all descriptors, providing common functionality.
/// </summary>
- /// <typeparam name="TProto">Type of the protocol buffer form of this descriptor</typeparam>
- /// <typeparam name="TOptions">Type of the options protocol buffer for this descriptor</typeparam>
- public abstract class DescriptorBase<TProto, TOptions> : IDescriptor<TProto>
- where TProto : IMessage, IDescriptorProto<TOptions>
+ public abstract class DescriptorBase : IDescriptor
{
- private TProto proto;
private readonly FileDescriptor file;
private readonly string fullName;
+ private readonly int index;
- protected DescriptorBase(TProto proto, FileDescriptor file, string fullName)
+ internal DescriptorBase(FileDescriptor file, string fullName, int index)
{
- this.proto = proto;
this.file = file;
this.fullName = fullName;
+ this.index = index;
}
- internal virtual void ReplaceProto(TProto newProto)
- {
- this.proto = newProto;
- }
-
- protected static string ComputeFullName(FileDescriptor file, MessageDescriptor parent, string name)
- {
- if (parent != null)
- {
- return parent.FullName + "." + name;
- }
- if (file.Package.Length > 0)
- {
- return file.Package + "." + name;
- }
- return name;
- }
-
- IMessage IDescriptor.Proto
- {
- get { return proto; }
- }
-
- /// <summary>
- /// Returns the protocol buffer form of this descriptor.
- /// </summary>
- public TProto Proto
+ /// <value>
+ /// The index of this descriptor within its parent descriptor.
+ /// </value>
+ /// <remarks>
+ /// This returns the index of this descriptor within its parent, for
+ /// this descriptor's type. (There can be duplicate values for different
+ /// types, e.g. one enum type with index 0 and one message type with index 0.)
+ /// </remarks>
+ public int Index
{
- get { return proto; }
+ get { return index; }
}
- public TOptions Options
- {
- get { return proto.Options; }
- }
+ public abstract string Name { get; }
/// <summary>
/// The fully qualified name of the descriptor's target.
@@ -98,14 +73,6 @@ namespace Google.Protobuf.Descriptors
get { return fullName; }
}
- /// <summary>
- /// The brief name of the descriptor's target.
- /// </summary>
- public string Name
- {
- get { return proto.Name; }
- }
-
/// <value>
/// The file this descriptor was declared in.
/// </value>