Interface IResolver
- Namespace
- Invex.Rez.Abstraction
- Assembly
- Invex.Rez.dll
Provides functionality for resolving variables and functions in a Rez template into an output string.
[PublicAPI]
public interface IResolver
Methods
AddSource(IResolverSource)
Adds a new source to the resolver.
If the source has already been added, this method does nothing.
IResolver AddSource(IResolverSource source)
Parameters
sourceIResolverSourceThe 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.
IResolver RemoveSource(IResolverSource source)
Parameters
sourceIResolverSourceThe source to remove.
Returns
- IResolver
The resolver instance, allowing calls to be chained.
Resolve(string?)
Resolves variables and functions within the given template text.
string? Resolve(string? input)
Parameters
inputstringThe template text containing variables and/or functions to be resolved.
Returns
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.