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
TThe 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
namestringThe name of this context value.
expressionstringThe expression string to parse and evaluate.
parserIParserThe 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
Expression
Gets the original expression string used to create this context value.
public string Expression { get; }
Property Value
Name
Gets the name of this context value.
public string Name { get; }
Property Value
Tree
Gets the parsed expression tree ready for evaluation.
public IExpression Tree { get; }
Property Value
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
inputTThe root context object.
funcFunc<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
inputTThe root context object.
funcFunc<string, T, Task<object>>Async function to resolve variable values during evaluation.