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

    public sealed class CustomOptions

Container for a set of custom options specified within a message, field etc.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> CustomOptions

## Inherited Members

[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

## Remarks


This type is publicly immutable, but internally mutable. It is only populated
by the descriptor parsing code - by the time any user code is able to see an instance,
it will be fully initialized.


If an option is requested using the incorrect method, an answer may still be returned: all
of the numeric types are represented internally using 64-bit integers, for example. It is up to
the caller to ensure that they make the appropriate method call for the option they're interested in.
Note that enum options are simply stored as integers, so the value should be fetched using
[TryGetInt32(int, out int)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.Reflection.CustomOptions#Google_Protobuf_Reflection_CustomOptions_TryGetInt32_System_Int32_System_Int32__) and then cast appropriately.


Repeated options are currently not supported. Asking for a single value of an option
which was actually repeated will return the last value, except for message types where
all the set values are merged together.

## Methods

### TryGetBool(int, out bool)

    public bool TryGetBool(int field, out bool value)

Retrieves a Boolean value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.boolean` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetBytes(int, out ByteString)

    public bool TryGetBytes(int field, out ByteString value)

Retrieves a bytes value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetDouble(int, out double)

    public bool TryGetDouble(int field, out double value)

Retrieves a 64-bit floating point value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.double` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetFixed32(int, out uint)

    public bool TryGetFixed32(int field, out uint value)

Retrieves an unsigned 32-bit integer value for the specified option field,
assuming a fixed-length representation.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint32` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetFixed64(int, out ulong)

    public bool TryGetFixed64(int field, out ulong value)

Retrieves an unsigned 64-bit integer value for the specified option field,
assuming a fixed-length representation.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint64` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetFloat(int, out float)

    public bool TryGetFloat(int field, out float value)

Retrieves a 32-bit floating point value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.single` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetInt32(int, out int)

    public bool TryGetInt32(int field, out int value)

Retrieves a signed 32-bit integer value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetInt64(int, out long)

    public bool TryGetInt64(int field, out long value)

Retrieves a signed 64-bit integer value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetMessage\<T\>(int, out T)

    public bool TryGetMessage<T>(int field, out T value) where T : class, IMessage, new()

Retrieves a message value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `T` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

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

### TryGetSFixed32(int, out int)

    public bool TryGetSFixed32(int field, out int value)

Retrieves a signed 32-bit integer value for the specified option field,
assuming a fixed-length representation.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetSFixed64(int, out long)

    public bool TryGetSFixed64(int field, out long value)

Retrieves a signed 64-bit integer value for the specified option field,
assuming a fixed-length representation.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetSInt32(int, out int)

    public bool TryGetSInt32(int field, out int value)

Retrieves a signed 32-bit integer value for the specified option field,
assuming a zigzag encoding.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int32` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetSInt64(int, out long)

    public bool TryGetSInt64(int field, out long value)

Retrieves a signed 64-bit integer value for the specified option field,
assuming a zigzag encoding.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.int64` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetString(int, out string)

    public bool TryGetString(int field, out string value)

Retrieves a string value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.string` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetUInt32(int, out uint)

    public bool TryGetUInt32(int field, out uint value)

Retrieves an unsigned 32-bit integer value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint32` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |

### TryGetUInt64(int, out ulong)

    public bool TryGetUInt64(int field, out ulong value)

Retrieves an unsigned 64-bit integer value for the specified option field.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `field` | `https://learn.microsoft.com/dotnet/api/system.int32` The field to fetch the value for. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.uint64` The output variable to populate. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` | `true` if a suitable value for the field was found; `false` otherwise. |