Table of Contents

Class ExpressionContextValue<T>

Namespace
Albatross.Expression.Context
Assembly
Albatross.Expression.dll

Context value that represents a variable defined by an expression. Parses the expression into an abstract syntax tree and evaluates it dynamically when requested.

public class ExpressionContextValue<T> : IContextValue<T>

Type Parameters

T

The type of the root context object.

Inheritance
ExpressionContextValue<T>
Implements
Inherited Members
Extension Methods

Constructors

ExpressionContextValue(string, string, IParser)

Initializes a new instance of the ExpressionContextValue class. Parses the expression, identifies variable dependencies, and builds the evaluation tree.

public ExpressionContextValue(string name, string expression, IParser parser)

Parameters

name string

The name of this context value.

expression string

The expression string to parse and evaluate.

parser IParser

The parser to use for tokenizing and building the expression tree.

Properties

Dependees

Gets the set of variable names that this expression depends on. Used for dependency tracking and circular reference detection.

public ISet<string> Dependees { get; }

Property Value

ISet<string>

Expression

Gets the original expression string used to create this context value.

public string Expression { get; }

Property Value

string

Name

Gets the name of this context value.

public string Name { get; }

Property Value

string

Tree

Gets the parsed expression tree ready for evaluation.

public IExpression Tree { get; }

Property Value

IExpression

Methods

GetValue(T, Func<string, T, object>)

Evaluates the expression tree to get the current value. Uses the provided function to resolve variable references during evaluation.

public object GetValue(T input, Func<string, T, object> func)

Parameters

input T

The root context object.

func Func<string, T, object>

Function to resolve variable values during evaluation.

Returns

object

The result of evaluating the expression.

GetValueAsync(T, Func<string, T, Task<object>>)

Asynchronously evaluates the expression tree to get the current value. Uses the provided async function to resolve variable references during evaluation.

public Task<object> GetValueAsync(T input, Func<string, T, Task<object>> func)

Parameters

input T

The root context object.

func Func<string, T, Task<object>>

Async function to resolve variable values during evaluation.

Returns

Task<object>

A task representing the asynchronous evaluation operation.