public sealed class PathTemplate
Represents a path template used for resource names which may be composed of multiple IDs.
Namespace
Google.Api.GaxAssembly
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/
*
.
template
Properties
ParameterCount
public int ParameterCount { get; }
The number of parameter segments (regular wildcards or path wildcards, named or unnamed) in the template.
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
.
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
resourceIds
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[]) 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
ParseName(string)
public TemplatedResourceName ParseName(string name)
Attempts to parse the given resource name against this template, throwing ArgumentException on failure.
name
ToString()
public override string ToString()
Returns the textual representation of this template.
The same textual representation that this template was initially constructed with.
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.
name
result
Although this method returns null
if a name is passed in which doesn't match the template,
it still throws ArgumentNullException
if name
is null, as this would
usually indicate a programming error rather than a data error.