# Class OneofDescriptor (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.OneofDescriptor)
- [3.23.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.23.0/Google.Protobuf.Reflection.OneofDescriptor)
- [3.15.8](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/3.15.8/Google.Protobuf.Reflection.OneofDescriptor)

    public sealed class OneofDescriptor : DescriptorBase, IDescriptor

Describes a "oneof" field collection in a message type: a set of
fields of which at most one can be set in any particular message.

## 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) \> OneofDescriptor

## Implements

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

## 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 OneofAccessor Accessor { get; }

Gets an accessor for reflective access to the values associated with the oneof
in a particular message.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.OneofAccessor` | The accessor used for reflective access. |

**Remarks**
In descriptors for generated code, the value returned by this property will always be non-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.

### ContainingType

    public MessageDescriptor ContainingType { get; }

Gets the message type containing this oneof.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.MessageDescriptor` | The message type containing this oneof. |

### CustomOptions

    [Obsolete("CustomOptions are obsolete. Use the GetOptions method.")]
    public CustomOptions CustomOptions { get; }

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

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

### Fields

    public IList<FieldDescriptor> Fields { get; }

Gets the fields within this oneof, in declaration order.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.FieldDescriptor` | The fields within this oneof, in declaration order. |

### IsSynthetic

    public bool IsSynthetic { get; }

Returns `true` if this oneof is a synthetic oneof containing a proto3 optional field;
`false` otherwise.

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

### 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)

## Methods

### GetOption\<T\>(Extension\<OneofOptions, T\>)

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

Gets a single value oneof 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.OneofOptions` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` |   |

### GetOption\<T\>(RepeatedExtension\<OneofOptions, T\>)

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

Gets a repeated value oneof 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.OneofOptions` |

| **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 OneofOptions GetOptions()

The `OneofOptions`, 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.OneofOptions` |   |

### ToProto()

    public OneofDescriptorProto ToProto()

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