Table of Contents

Class Resolver

Namespace
Invex.Rez.Implementation
Assembly
Invex.Rez.dll

The default implementation of IResolver.
Resolves variables (e.g., {name}) and functions (e.g., {name(args)}) in a Rez template by querying registered IResolverSource instances in the order they were added.

[PublicAPI]
public sealed class Resolver : IResolver
Inheritance
object
Resolver
Implements

Remarks

Resolution is recursive: if a resolved value itself contains variables or functions, they are resolved as well, until the text no longer changes. A variable whose value is its own placeholder (e.g., a = {a}) is left unchanged; a cycle whose output keeps changing (e.g., a = {b}, b = {a}) exceeds the maximum depth and throws a RezResolutionException.

Methods

AddSource(IResolverSource)

Adds a new source to the resolver.
If the source has already been added, this method does nothing.

public IResolver AddSource(IResolverSource source)

Parameters

source IResolverSource

The source to add.

Returns

IResolver

The resolver instance, allowing calls to be chained.

Remarks

The order in which sources are added is important - when resolving a variable or function, sources are queried in the order they were added, and the first non-null result wins.

RemoveSource(IResolverSource)

Removes a source from the resolver.
If the source was not added, this method does nothing.

public IResolver RemoveSource(IResolverSource source)

Parameters

source IResolverSource

The source to remove.

Returns

IResolver

The resolver instance, allowing calls to be chained.

Resolve(string?)

Resolves variables and functions within the given template text.

public string? Resolve(string? input)

Parameters

input string

The template text containing variables and/or functions to be resolved.

Returns

string

The resolved output text, or null if input is null.

Examples

The following example demonstrates how to use the Resolve method to resolve variables and functions:

resolverInstance.Resolve("The {color} {animal} jumps over the \\{escapedVariable\\} and calls {function()}.");

The output could look like: "The brown fox jumps over the \{escapedVariable\} and calls the-function-result."

Remarks

Variables are written as {name} and functions as {name(args)}.
Braces can be escaped with a backslash (e.g., {notAVariable}) to exclude them from resolution; the backslashes are preserved in the output.
Resolution is recursive: if a resolved value itself contains variables or functions, they are resolved as well, until the text no longer changes. A placeholder whose value is its own placeholder text (e.g., a = {a}) is left as is; a cycle whose output keeps changing throws.
Placeholders that no source can resolve are left in the output unchanged.

Exceptions

RezResolutionException

Thrown if recursion exceeds a depth of 4096 (a resolved value containing a placeholder that is resolved in turn, and so on), such as for a cycle like a = {b}, b = {a}. The number of placeholders in a template is not limited.