Class PrefixExpression
- Namespace
- Albatross.Expression.Prefix
- Assembly
- Albatross.Expression.dll
Base implementation for prefix function expressions that operate on multiple operands.
public class PrefixExpression : IPrefixExpression, IExpression, IToken
- Inheritance
-
PrefixExpression
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
PrefixExpression(string, int, int)
Initializes a new instance of the PrefixExpression class.
public PrefixExpression(string name, int minOperandCount, int maxOperandCount)
Parameters
namestringThe name of the prefix function.
minOperandCountintThe minimum number of operands required.
maxOperandCountintThe maximum number of operands accepted.
Properties
MaxOperandCount
The maximum number of operands this function accepts.
public int MaxOperandCount { get; }
Property Value
MinOperandCount
The minimum number of operands this function requires.
public int MinOperandCount { get; }
Property Value
Name
The name of the prefix function.
public string Name { get; }
Property Value
Operands
The list of operand expressions passed to this function.
public IReadOnlyList<IExpression> Operands { get; set; }
Property Value
Token
The token representation, which is the same as the Name.
public string Token { get; }
Property Value
Methods
Eval(Func<string, object>)
Evaluates the expression synchronously using the provided context function.
public object Eval(Func<string, object> context)
Parameters
Returns
- object
The result of evaluating the expression.
EvalAsync(Func<string, Task<object>>)
Evaluates the expression asynchronously using the provided context function.
public Task<object> EvalAsync(Func<string, Task<object>> context)
Parameters
contextFunc<string, Task<object>>A function that asynchronously resolves variable names to their values.
Returns
Run(List<object>)
Executes the prefix function with the evaluated operand values. Derived classes should override this method to implement specific function logic.
protected virtual object Run(List<object> operands)
Parameters
Returns
- object
The result of the function.
Text()
Returns the text representation of this token for display or serialization purposes.
public string Text()
Returns
- string
A string representation of the token.
ValidateOperands()
Validates that the number of operands is within the allowed range.
protected void ValidateOperands()
Exceptions
- OperandException
Thrown when the operand count is outside the valid range.