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
Properties
Left
The left operand of the infix operation.
public IExpression? Left { get; set; }
Property Value
Operator
The operator symbol for this infix operation.
public string Operator { get; }
Property Value
Precedence
The precedence level of this operation for proper evaluation order.
public int Precedence { get; }
Property Value
RequiredLeft
Gets the required left operand, throwing an exception if it's null.
public IExpression RequiredLeft { get; }
Property Value
RequiredRight
Gets the required right operand, throwing an exception if it's null.
public IExpression RequiredRight { get; }
Property Value
Right
The right operand of the infix operation.
public IExpression? Right { get; set; }
Property Value
Token
The token representation, which is the same as the Operator.
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(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
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.