# Class FieldDescriptor (3.27.1)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [3.27.1 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptor)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.Reflection.FieldDescriptor)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.Reflection.FieldDescriptor)

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

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

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> [DescriptorBase](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase) \> FieldDescriptor

## Implements

[IDescriptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.IDescriptor), [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable-1)[FieldDescriptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptor)

## Inherited Members

[DescriptorBase.Index](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase#Google_Protobuf_Reflection_DescriptorBase_Index) [DescriptorBase.FullName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase#Google_Protobuf_Reflection_DescriptorBase_FullName) [DescriptorBase.File](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase#Google_Protobuf_Reflection_DescriptorBase_File) [DescriptorBase.Declaration](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase#Google_Protobuf_Reflection_DescriptorBase_Declaration) [object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Protobuf.Reflection](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection)

## Assembly

Google.Protobuf.dll

## Properties

### Accessor

    public IFieldAccessor Accessor { get; }

Returns the accessor for this field.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.IFieldAccessor` |   |

**Remarks**
While a [FieldDescriptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.CustomOptions` |   |

### EnumType

    public EnumDescriptor EnumType { get; }

For enum fields, returns the field's type.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.EnumDescriptor` |   |

### ExtendeeType

    public MessageDescriptor ExtendeeType { get; }

For extension fields, returns the extended type

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Extension` |   |

### FieldNumber

    public int FieldNumber { get; }

Returns the field number declared in the proto file.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### FieldType

    public FieldType FieldType { get; }

Returns the type of the field.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.IFieldAccessor#Google_Protobuf_Reflection_IFieldAccessor_Clear_Google_Protobuf_IMessage_) and [HasValue(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.IFieldAccessor#Google_Protobuf_Reflection_IFieldAccessor_HasValue_Google_Protobuf_IMessage_)
on this field's accessor with a suitable message.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### IsExtension

    public bool IsExtension { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### IsMap

    public bool IsMap { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### IsPacked

    public bool IsPacked { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### IsRepeated

    public bool IsRepeated { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### IsRequired

    public bool IsRequired { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### MessageType

    public MessageDescriptor MessageType { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.MessageDescriptor` |   |

### Name

    public override string Name { get; }

The brief name of the descriptor's target.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

**Overrides** [DescriptorBase.Name](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.DescriptorBase#Google_Protobuf_Reflection_DescriptorBase_Name)

### PropertyName

    public string PropertyName { get; }

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

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptor#Google_Protobuf_Reflection_FieldDescriptor_ContainingType) of
both fields must be the same.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptor` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### 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` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Extension-2https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldOptions` |

| **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` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.RepeatedExtension-2https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldOptions` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Collections.RepeatedField-1` |   |

| **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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldOptions` |   |

### ToProto()

    public FieldDescriptorProto ToProto()

Returns a clone of the underlying [FieldDescriptorProto](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.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** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptorProto` | A protobuf representation of this field descriptor. |