Show / Hide Table of Contents

Class PathTemplate

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

Inheritance
System.Object
PathTemplate
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Google.Api.Gax
Assembly: Google.Api.Gax.dll
Syntax
public sealed class PathTemplate
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)

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

Declaration
public PathTemplate(string template)
Parameters
Type Name Description
System.String template

The textual representation of the template. Must not be null.

Properties

ParameterCount

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

Declaration
public int ParameterCount { get; }
Property Value
Type Description
System.Int32

ParameterNames

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

Declaration
public IReadOnlyList<string> ParameterNames { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyList<System.String>

Methods

Expand(String[])

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

Declaration
public string Expand(params string[] resourceIds)
Parameters
Type Name Description
System.String[] resourceIds

The resource IDs to use to populate the parameters in this template. Must not be null.

Returns
Type Description
System.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, String[]) to specify a service name.

ExpandWithService(String, String[])

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

Declaration
public string ExpandWithService(string serviceName, params string[] resourceIds)
Parameters
Type Name Description
System.String serviceName

The service name, which may be null.

System.String[] resourceIds

The resource IDs to use to populate the parameters in this template. Must not be null.

Returns
Type Description
System.String

The string representation of the resource name.

ParseName(String)

Attempts to parse the given resource name against this template, throwing System.ArgumentException on failure.

Declaration
public TemplatedResourceName ParseName(string name)
Parameters
Type Name Description
System.String name

The resource name to parse against this template. Must not be null.

Returns
Type Description
TemplatedResourceName

The parsed name as a TemplatedResourceName.

ToString()

Returns the textual representation of this template.

Declaration
public override string ToString()
Returns
Type Description
System.String

The same textual representation that this template was initially constructed with.

Overrides
System.Object.ToString()

TryParseName(String, out TemplatedResourceName)

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

Declaration
public bool TryParseName(string name, out TemplatedResourceName result)
Parameters
Type Name Description
System.String name

The resource name to parse against this template. Must not be null.

TemplatedResourceName result

When this method returns, the parsed resource name or null if parsing fails.

Returns
Type Description
System.Boolean

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 System.ArgumentNullException if name is null, as this would usually indicate a programming error rather than a data error.

Back to top