Table of Contents

Class InfixExpression

Namespace
Albatross.Expression.Infix
Assembly
Albatross.Expression.dll

Base implementation for infix binary operation expressions.

public class InfixExpression : IInfixExpression, IExpression, IToken, IHasPrecedence
Inheritance
InfixExpression
Implements
Derived
Inherited Members
Extension Methods

Constructors

InfixExpression(string, int)

Initializes a new instance of the InfixExpression class.

public InfixExpression(string operatorText, int precedence)

Parameters

operatorText string

The operator symbol.

precedence int

The precedence level for this operation.

Properties

Left

The left operand of the infix operation.

public IExpression? Left { get; set; }

Property Value

IExpression

Operator

The operator symbol for this infix operation.

public string Operator { get; }

Property Value

string

Precedence

The precedence level of this operation for proper evaluation order.

public int Precedence { get; }

Property Value

int

RequiredLeft

Gets the required left operand, throwing an exception if it's null.

public IExpression RequiredLeft { get; }

Property Value

IExpression

RequiredRight

Gets the required right operand, throwing an exception if it's null.

public IExpression RequiredRight { get; }

Property Value

IExpression

Right

The right operand of the infix operation.

public IExpression? Right { get; set; }

Property Value

IExpression

Token

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

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(object, object)

Executes the infix operation with the evaluated left and right operands. Derived classes should override this method to implement specific operations.

protected virtual object Run(object left, object right)

Parameters

left object

The evaluated left operand value.

right object

The evaluated right operand value.

Returns

object

The result of the operation.

Text()

Returns the text representation of this token for display or serialization purposes.

public string Text()

Returns

string

A string representation of the token.