Class UnaryExpression
- Namespace
- Albatross.Expression.Unary
- Assembly
- Albatross.Expression.dll
Base implementation for unary operation expressions that operate on a single operand.
public class UnaryExpression : IUnaryExpression, IExpression, IToken, IHasPrecedence
- Inheritance
-
UnaryExpression
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
UnaryExpression(string, int)
Initializes a new instance of the UnaryExpression class.
public UnaryExpression(string operatorOperator, int precedence)
Parameters
operatorOperatorstringThe operator symbol.
precedenceintThe precedence level for this operation.
Properties
Operand
The operand that this unary operation applies to.
public IExpression? Operand { get; set; }
Property Value
Operator
The operator symbol for this unary operation.
public string Operator { get; }
Property Value
Precedence
The precedence level of this operation for proper evaluation order.
public int Precedence { get; }
Property Value
RequiredOperand
Gets the required operand, throwing an exception if it's null.
public IExpression RequiredOperand { get; }
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)
protected virtual object Run(object operand)
Parameters
operandobject
Returns
Text()
Returns the text representation of this token for display or serialization purposes.
public string Text()
Returns
- string
A string representation of the token.