• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2008 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using System.Collections.Generic;
11 using System.Diagnostics;
12 
13 namespace Google.Protobuf.Reflection
14 {
15     // Implementation note: The descriptors which don't derive from this class are FileDescriptor
16     // and FeatureSetDescriptor - the latter of which isn't a descriptor in exactly the same way
17     // that the others are anyway.
18 
19     /// <summary>
20     /// Base class for nearly all descriptors, providing common functionality.
21     /// </summary>
22     [DebuggerDisplay("Type = {GetType().Name,nq}, FullName = {FullName}")]
23     public abstract class DescriptorBase : IDescriptor
24     {
DescriptorBase(FileDescriptor file, string fullName, int index, FeatureSetDescriptor features)25         internal DescriptorBase(FileDescriptor file, string fullName, int index, FeatureSetDescriptor features)
26         {
27             File = file;
28             FullName = fullName;
29             Index = index;
30             Features = features;
31         }
32 
33         /// <summary>
34         /// The feature set for this descriptor, including inherited features.
35         /// This is internal as external users should use the properties on individual
36         /// descriptor types (e.g. FieldDescriptor.IsPacked) rather than querying features directly.
37         /// </summary>
38         internal FeatureSetDescriptor Features { get; }
39 
40         /// <value>
41         /// The index of this descriptor within its parent descriptor.
42         /// </value>
43         /// <remarks>
44         /// This returns the index of this descriptor within its parent, for
45         /// this descriptor's type. (There can be duplicate values for different
46         /// types, e.g. one enum type with index 0 and one message type with index 0.)
47         /// </remarks>
48         public int Index { get; }
49 
50         /// <summary>
51         /// Returns the name of the entity (field, message etc) being described.
52         /// </summary>
53         public abstract string Name { get; }
54 
55         /// <summary>
56         /// The fully qualified name of the descriptor's target.
57         /// </summary>
58         public string FullName { get; }
59 
60         /// <value>
61         /// The file this descriptor was declared in.
62         /// </value>
63         public FileDescriptor File { get; }
64 
65         /// <summary>
66         /// The declaration information about the descriptor, or null if no declaration information
67         /// is available for this descriptor.
68         /// </summary>
69         /// <remarks>
70         /// This information is typically only available for dynamically loaded descriptors,
71         /// for example within a protoc plugin where the full descriptors, including source info,
72         /// are passed to the code by protoc.
73         /// </remarks>
74         public DescriptorDeclaration Declaration => File.GetDeclaration(this);
75 
76         /// <summary>
77         /// Retrieves the list of nested descriptors corresponding to the given field number, if any.
78         /// If the field is unknown or not a nested descriptor list, return null to terminate the search.
79         /// The default implementation returns null.
80         /// </summary>
GetNestedDescriptorListForField(int fieldNumber)81         internal virtual IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(int fieldNumber) => null;
82     }
83 }