Class FieldDescriptor (3.27.1)

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

Namespace

Google.Protobuf.Reflection

Assembly

Google.Protobuf.dll

Properties

Accessor

public IFieldAccessor Accessor { get; }

Returns the accessor for this field.

Property Value
Type Description
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
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

[Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")]
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
int

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
bool

IsExtension

public bool IsExtension { get; }

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

Property Value
Type Description
bool

IsMap

public bool IsMap { get; }

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

Property Value
Type Description
bool

IsPacked

public bool IsPacked { get; }

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

Property Value
Type Description
bool

IsRepeated

public bool IsRepeated { get; }

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

Property Value
Type Description
bool

IsRequired

public bool IsRequired { get; }

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

Property Value
Type Description
bool

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
Overrides

PropertyName

public string PropertyName { get; }

The name of the property in the ContainingType.ClrType class.

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
int

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

[Obsolete("GetOption is obsolete. Use the GetOptions() method.")]
public T GetOption<T>(Extension<FieldOptions, T> extension)

Gets a single value field option for this descriptor

Parameter
Name Description
extension ExtensionFieldOptions
Returns
Type Description
T
Type Parameter
Name Description
T

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

[Obsolete("GetOption is obsolete. Use the GetOptions() method.")]
public RepeatedField<T> GetOption<T>(RepeatedExtension<FieldOptions, T> extension)

Gets a repeated value field option for this descriptor

Parameter
Name Description
extension RepeatedExtensionFieldOptions
Returns
Type Description
RepeatedField
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

ToProto()

public FieldDescriptorProto ToProto()

Returns a clone of the underlying FieldDescriptorProto describing this field. Note that a copy is taken every time this method is called, so clients using it frequently (and not modifying it) may want to cache the returned value.

Returns
Type Description
FieldDescriptorProto

A protobuf representation of this field descriptor.