# Class RoutingHeaderExtractor&lt;TRequest&gt; (4.10.0)

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

- [4.10.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [4.8.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.8.0/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.4.0/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.3.1/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [4.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.2.0/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [4.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/4.0.0/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)
- [3.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/3.2.0/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1)

    public sealed class RoutingHeaderExtractor<TRequest>

Collects the explicit routing header extraction instructions and
extracts the routing header value from a specific request
using these instructions.
This class is immutable.

## Inheritance

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

## 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.Api.Gax.Grpc](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc)

## Assembly

Google.Api.Gax.Grpc.dll

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `TRequest` |   |

## Constructors

### RoutingHeaderExtractor()

    public RoutingHeaderExtractor()

Create a new RoutingHeaderExtractor with no patterns. (This cannot be used
to extract headers; new instances must be created with [WithExtractedParameter(string, string, Func\<TRequest, string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1#Google_Api_Gax_Grpc_RoutingHeaderExtractor_1_WithExtractedParameter_System_String_System_String_System_Func__0_System_String__)
which provides patterns to use to extract values.)

## Methods

### ExtractHeader(TRequest)

    public string ExtractHeader(TRequest request)

Extracts the routing header value to apply based on a request.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `TRequest` A request to extract the routing header parameters and values from |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` | The value to use for the routing header. This may contain multiple \&-separated parameters. |

### FormatRoutingHeaderValue(object)

    public static string FormatRoutingHeaderValue(object value)

Returns a string representation of the given value, suitable for including in a routing header.
(This method does not perform URI encoding; it is expected that the result of this method will either be
used in [WithExtractedParameter(string, string, Func\<TRequest, string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1#Google_Api_Gax_Grpc_RoutingHeaderExtractor_1_WithExtractedParameter_System_String_System_String_System_Func__0_System_String__), or as an argument to
[WithGoogleRequestParam(string, Func\<TRequest, string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.ApiCall-2#Google_Api_Gax_Grpc_ApiCall_2_WithGoogleRequestParam_System_String_System_Func__0_System_String__).)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.object` The value to format. May be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` | The formatted value, or null if `value` is null. |

### WithExtractedParameter(string, string, Func\<TRequest, string\>)

    public RoutingHeaderExtractor<TRequest> WithExtractedParameter(string paramName, string extractionRegex, Func<TRequest, string> selector)

Returns a new instance with the same parameter extractors as this one, with an additional one specified as arguments.
The extractions follow the "last successfully matched wins" rule for
conflict resolution when there are multiple extractions for the same parameter name.
(See `google/api/routing.proto` for further details.) If multiple parameters
with different names are present, the extracted header will contain them in the order
in which they have been added with this method, based on the first occurrence of
each parameter name.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `paramName` | `https://learn.microsoft.com/dotnet/api/system.string` The name of the parameter in the routing header. |
| `extractionRegex` | `https://learn.microsoft.com/dotnet/api/system.string` The regular expression (in string form) used to extract the value of the parameter. Must have exactly one capturing group (in addition to the implicit "group 0" which captures the whole match). |
| `selector` | `https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.string` A function to call on each request, to determine the string to extract the header value from. The parameter must not be null, but may return null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.RoutingHeaderExtractor-1` |   |