Class FieldDescriptor

public sealed class FieldDescriptor : DescriptorBase, IDescriptor, IComparable<FieldDescriptor>

Descriptor for a field or extension within a message in a .proto file.

Inheritance

Object > DescriptorBase > FieldDescriptor

Implements

IDescriptor, IComparable<FieldDescriptor>

Namespace

Google.Protobuf.Reflection

Assembly

Google.Protobuf.dll

Properties

Accessor

public IFieldAccessor Accessor { get; }

Returns the accessor for this field.

Property Value
TypeDescription
IFieldAccessor
Remarks

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
TypeDescription
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
TypeDescription
MessageDescriptor

CustomOptions

public CustomOptions CustomOptions { get; }

The (possibly empty) set of custom options for this field.

Property Value
TypeDescription
CustomOptions

EnumType

public EnumDescriptor EnumType { get; }

For enum fields, returns the field's type.

Property Value
TypeDescription
EnumDescriptor

ExtendeeType

public MessageDescriptor ExtendeeType { get; }

For extension fields, returns the extended type

Property Value
TypeDescription
MessageDescriptor

Extension

public Extension Extension { get; }

An extension identifier for this field, or null if this field isn't an extension.

Property Value
TypeDescription
Extension

FieldNumber

public int FieldNumber { get; }

Returns the field number declared in the proto file.

Property Value
TypeDescription
Int32

FieldType

public FieldType FieldType { get; }

Returns the type of the field.

Property Value
TypeDescription
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
TypeDescription
Boolean

IsExtension

public bool IsExtension { get; }

Returns true if this field extends another message type; false otherwise.

Property Value
TypeDescription
Boolean

IsMap

public bool IsMap { get; }

Returns true if this field is a map field; false otherwise.

Property Value
TypeDescription
Boolean

IsPacked

public bool IsPacked { get; }

Returns true if this field is a packed, repeated field; false otherwise.

Property Value
TypeDescription
Boolean

IsRepeated

public bool IsRepeated { get; }

Returns true if this field is a repeated field; false otherwise.

Property Value
TypeDescription
Boolean

IsRequired

public bool IsRequired { get; }

Returns true if this field is a required field; false otherwise.

Property Value
TypeDescription
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
TypeDescription
String

MessageType

public MessageDescriptor MessageType { get; }

For embedded message and group fields, returns the field's type.

Property Value
TypeDescription
MessageDescriptor

Name

public override string Name { get; }

The brief name of the descriptor's target.

Property Value
TypeDescription
String
Overrides

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
TypeDescription
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
TypeNameDescription
FieldDescriptorother
Returns
TypeDescription
Int32

GetOption<T>(Extension<FieldOptions, T>)

public T GetOption<T>(Extension<FieldOptions, T> extension)

Gets a single value field option for this descriptor

Parameter
TypeNameDescription
Extension<FieldOptions, T>extension
Returns
TypeDescription
T
Type Parameter
NameDescription
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
TypeNameDescription
RepeatedExtension<FieldOptions, T>extension
Returns
TypeDescription
RepeatedField<T>
Type Parameter
NameDescription
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
TypeDescription
FieldOptions

Implements

IComparable<>