4.10.0 (latest) 4.8.0 4.4.0 4.3.1 4.2.0 4.0.0 3.2.0

    public sealed class PathTemplate

Represents a path template used for resource names which may be composed of multiple IDs.

## Inheritance

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

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

## Namespace

[Google.Api.Gax](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.md.txt)

## Assembly

Google.Api.Gax.dll

## Remarks


Templates use a subset of the syntax of the API platform. See
<https://github.com/googleapis/googleapis/blob/master/google/api/http.proto>
for details of the API platform.


This class performs no URL escaping or unescaping. It is designed for use within GRPC, where no
URL encoding is required.

## Constructors

### PathTemplate(string)

    public PathTemplate(string template)

Constructs a template from its textual representation, such as `shelves//books/*`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `template` | `string` The textual representation of the template. Must not be null. |

## Properties

### ParameterCount

    public int ParameterCount { get; }

The number of parameter segments (regular wildcards or path wildcards, named or unnamed) in the template.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `int` |   |

### ParameterNames

    public IReadOnlyList<string> ParameterNames { get; }

The names of the parameters within the template. This collection has one element per parameter,
but unnamed parameters have a name of `null`.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `IReadOnlyListstring` |   |

## Methods

### Expand(params string\[\])

    public string Expand(params string[] resourceIds)

Validates that the given resource IDs are valid for this template, and returns a string representation

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `resourceIds` | `string` The resource IDs to use to populate the parameters in this template. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` | The string representation of the resource name. |

**Remarks**
This is equivalent to calling `new ResourceName(template, resourceIds).ToString()`, but simpler in
calling code and more efficient in terms of memory allocation.


This method assumes no service name is required. Call [ExpandWithService(string, params string\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.PathTemplate.md.txt#Google_Api_Gax_PathTemplate_ExpandWithService_System_String_System_String___) to specify a service name.

### ExpandWithService(string, params string\[\])

    public string ExpandWithService(string serviceName, params string[] resourceIds)

Validates that the given resource IDs are valid for this template, and returns a string representation

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `serviceName` | `string` The service name, which may be null. |
| `resourceIds` | `string` The resource IDs to use to populate the parameters in this template. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` | The string representation of the resource name. |

### ParseName(string)

    public TemplatedResourceName ParseName(string name)

Attempts to parse the given resource name against this template, throwing [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) on failure.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The resource name to parse against this template. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TemplatedResourceName` | The parsed name as a [TemplatedResourceName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.TemplatedResourceName.md.txt). |

### ToString()

    public override string ToString()

Returns the textual representation of this template.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` | The same textual representation that this template was initially constructed with. |

**Overrides** [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

### TryParseName(string, out TemplatedResourceName)

    public bool TryParseName(string name, out TemplatedResourceName result)

Attempts to parse the given resource name against this template, returning `null` on failure.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `string` The resource name to parse against this template. Must not be null. |
| `result` | `TemplatedResourceName` When this method returns, the parsed resource name or `null` if parsing fails. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` | `true` if the name was parsed successfully; `false` otherwise. |

**Remarks** Although this method returns `null` if a name is passed in which doesn't match the template,
it still throws [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception) if `name` is null, as this would
usually indicate a programming error rather than a data error.