Table of Contents

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

name string

The name of the prefix function.

minOperandCount int

The minimum number of operands required.

maxOperandCount int

The maximum number of operands accepted.

Properties

MaxOperandCount

The maximum number of operands this function accepts.

public int MaxOperandCount { get; }

Property Value

int

MinOperandCount

The minimum number of operands this function requires.

public int MinOperandCount { get; }

Property Value

int

Name

The name of the prefix function.

public string Name { get; }

Property Value

string

Operands

The list of operand expressions passed to this function.

public IReadOnlyList<IExpression> Operands { get; set; }

Property Value

IReadOnlyList<IExpression>

Token

The token representation, which is the same as the Name.

public string Token { get; }

Property Value

string

Methods

Eval(Func<string, object>)

Evaluates the expression synchronously using the provided context function.

public object Eval(Func<string, object> context)

Parameters

context Func<string, object>

A function that resolves variable names to their values.

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

context Func<string, Task<object>>

A function that asynchronously resolves variable names to their values.

Returns

Task<object>

A task containing the result of evaluating the expression.

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

operands List<object>

The list of evaluated operand values.

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.