public sealed class FieldDescriptor : DescriptorBase, IDescriptor, IComparable<FieldDescriptor>
Descriptor for a field or extension within a message in a .proto file.
Namespace
Google.Protobuf.ReflectionAssembly
Google.Protobuf.dll
Properties
Accessor
public IFieldAccessor Accessor { get; }
Returns the accessor for this field.
Property Value | |
---|---|
Type | Description |
IFieldAccessor |
While a FieldDescriptor describes the field, it does not provide any way of obtaining or changing the value of the field within a specific message; that is the responsibility of the accessor.
In descriptors for generated code, the value returned by this property will be non-null for all regular fields. However, if a message containing a map field is introspected, the list of nested messages will include an auto-generated nested key/value pair message for the field. This is not represented in any generated type, and the value of the map field itself is represented by a dictionary in the reflection API. There are never instances of those "hidden" messages, so no accessor is provided and this property will return null.
In dynamically loaded descriptors, the value returned by this property will current be null; if and when dynamic messages are supported, it will return a suitable accessor to work with them.
ContainingOneof
public OneofDescriptor ContainingOneof { get; }
Returns the oneof containing this field, or null
if it is not part of a oneof.
Property Value | |
---|---|
Type | Description |
OneofDescriptor |
ContainingType
public MessageDescriptor ContainingType { get; }
Get the field's containing message type, or null
if it is a field defined at the top level of a file as an extension.
Property Value | |
---|---|
Type | Description |
MessageDescriptor |
CustomOptions
public CustomOptions CustomOptions { get; }
The (possibly empty) set of custom options for this field.
Property Value | |
---|---|
Type | Description |
CustomOptions |
EnumType
public EnumDescriptor EnumType { get; }
For enum fields, returns the field's type.
Property Value | |
---|---|
Type | Description |
EnumDescriptor |
ExtendeeType
public MessageDescriptor ExtendeeType { get; }
For extension fields, returns the extended type
Property Value | |
---|---|
Type | Description |
MessageDescriptor |
Extension
public Extension Extension { get; }
An extension identifier for this field, or null
if this field isn't an extension.
Property Value | |
---|---|
Type | Description |
Extension |
FieldNumber
public int FieldNumber { get; }
Returns the field number declared in the proto file.
Property Value | |
---|---|
Type | Description |
Int32 |
FieldType
public FieldType FieldType { get; }
Returns the type of the field.
Property Value | |
---|---|
Type | Description |
FieldType |
HasPresence
public bool HasPresence { get; }
Indicates whether this field supports presence, either implicitly (e.g. due to it being a message type field) or explicitly via Has/Clear members. If this returns true, it is safe to call Clear(IMessage) and HasValue(IMessage) on this field's accessor with a suitable message.
Property Value | |
---|---|
Type | Description |
Boolean |
IsExtension
public bool IsExtension { get; }
Returns true
if this field extends another message type; false
otherwise.
Property Value | |
---|---|
Type | Description |
Boolean |
IsMap
public bool IsMap { get; }
Returns true
if this field is a map field; false
otherwise.
Property Value | |
---|---|
Type | Description |
Boolean |
IsPacked
public bool IsPacked { get; }
Returns true
if this field is a packed, repeated field; false
otherwise.
Property Value | |
---|---|
Type | Description |
Boolean |
IsRepeated
public bool IsRepeated { get; }
Returns true
if this field is a repeated field; false
otherwise.
Property Value | |
---|---|
Type | Description |
Boolean |
IsRequired
public bool IsRequired { get; }
Returns true
if this field is a required field; false
otherwise.
Property Value | |
---|---|
Type | Description |
Boolean |
JsonName
public string JsonName { get; }
The effective JSON name for this field. This is usually the lower-camel-cased form of the field name,
but can be overridden using the json_name
option in the .proto file.
Property Value | |
---|---|
Type | Description |
String |
MessageType
public MessageDescriptor MessageType { get; }
For embedded message and group fields, returns the field's type.
Property Value | |
---|---|
Type | Description |
MessageDescriptor |
Name
public override string Name { get; }
The brief name of the descriptor's target.
Property Value | |
---|---|
Type | Description |
String |
RealContainingOneof
public OneofDescriptor RealContainingOneof { get; }
Returns the oneof containing this field if it's a "real" oneof, or null
if either this
field is not part of a oneof, or the oneof is synthetic.
Property Value | |
---|---|
Type | Description |
OneofDescriptor |
Methods
CompareTo(FieldDescriptor)
public int CompareTo(FieldDescriptor other)
Compares this descriptor with another one, ordering in "canonical" order
which simply means ascending order by field number. other
must be a field of the same type, i.e. the ContainingType of
both fields must be the same.
Parameter | |
---|---|
Name | Description |
other | FieldDescriptor |
Returns | |
---|---|
Type | Description |
Int32 |
GetOption<T>(Extension<FieldOptions, T>)
public T GetOption<T>(Extension<FieldOptions, T> extension)
Gets a single value field option for this descriptor
Parameter | |
---|---|
Name | Description |
extension | Extension<FieldOptions, T> |
Returns | |
---|---|
Type | Description |
T |
Type Parameter | |
---|---|
Name | Description |
T |
GetOption<T>(RepeatedExtension<FieldOptions, T>)
public RepeatedField<T> GetOption<T>(RepeatedExtension<FieldOptions, T> extension)
Gets a repeated value field option for this descriptor
Parameter | |
---|---|
Name | Description |
extension | RepeatedExtension<FieldOptions, T> |
Returns | |
---|---|
Type | Description |
RepeatedField<T> |
Type Parameter | |
---|---|
Name | Description |
T |
GetOptions()
public FieldOptions GetOptions()
The FieldOptions
, defined in descriptor.proto
.
If the options message is not present (i.e. there are no options), null
is returned.
Custom options can be retrieved as extensions of the returned message.
NOTE: A defensive copy is created each time this property is retrieved.
Returns | |
---|---|
Type | Description |
FieldOptions |