Table of Contents

Class AsyncExpression

Namespace
NCalc
Assembly
NCalc.Async.dll

This class represents a mathematical or logical expression that can be evaluated. It supports caching, custom parameter and function evaluation, and options for handling null parameters and iterating over parameter collections. The class manages the parsing, validation, and evaluation of expressions, and provides mechanisms for error detection and reporting.

public class AsyncExpression
Inheritance
AsyncExpression
Inherited Members

Constructors

AsyncExpression(LogicalExpression)

public AsyncExpression(LogicalExpression logicalExpression)

Parameters

logicalExpression LogicalExpression

AsyncExpression(LogicalExpression, AsyncExpressionContext?)

public AsyncExpression(LogicalExpression logicalExpression, AsyncExpressionContext? context = null)

Parameters

logicalExpression LogicalExpression
context AsyncExpressionContext

AsyncExpression(LogicalExpression, AsyncExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IAsyncEvaluationService)

public AsyncExpression(LogicalExpression logicalExpression, AsyncExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IAsyncEvaluationService evaluationService)

Parameters

logicalExpression LogicalExpression
context AsyncExpressionContext
factory ILogicalExpressionFactory
cache ILogicalExpressionCache
evaluationService IAsyncEvaluationService

AsyncExpression(LogicalExpression, ExpressionOptions, CultureInfo?)

public AsyncExpression(LogicalExpression logicalExpression, ExpressionOptions options = ExpressionOptions.None, CultureInfo? cultureInfo = null)

Parameters

logicalExpression LogicalExpression
options ExpressionOptions
cultureInfo CultureInfo

AsyncExpression(string)

public AsyncExpression(string expression)

Parameters

expression string

AsyncExpression(string, AsyncExpressionContext?)

public AsyncExpression(string expression, AsyncExpressionContext? context = null)

Parameters

expression string
context AsyncExpressionContext

AsyncExpression(string, AsyncExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IAsyncEvaluationService)

public AsyncExpression(string expression, AsyncExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IAsyncEvaluationService evaluationService)

Parameters

expression string
context AsyncExpressionContext
factory ILogicalExpressionFactory
cache ILogicalExpressionCache
evaluationService IAsyncEvaluationService

AsyncExpression(string, ExpressionOptions, CultureInfo?)

public AsyncExpression(string expression, ExpressionOptions options = ExpressionOptions.None, CultureInfo? cultureInfo = null)

Parameters

expression string
options ExpressionOptions
cultureInfo CultureInfo

Properties

CacheEnabled

Static property to enable or disable cache. Default Value: True

public static bool CacheEnabled { get; set; }

Property Value

bool

Context

protected AsyncExpressionContext Context { get; init; }

Property Value

AsyncExpressionContext

CultureInfo

Culture information for the expression evaluation.

public CultureInfo CultureInfo { get; set; }

Property Value

CultureInfo

DynamicParameters

public IDictionary<string, AsyncExpressionParameter> DynamicParameters { get; set; }

Property Value

IDictionary<string, AsyncExpressionParameter>

Error

public Exception? Error { get; }

Property Value

Exception

EvaluationService

protected IAsyncEvaluationService EvaluationService { get; }

Property Value

IAsyncEvaluationService

ExpressionString

Textual representation of the expression.

public string? ExpressionString { get; protected init; }

Property Value

string

Functions

public IDictionary<string, AsyncExpressionFunction> Functions { get; set; }

Property Value

IDictionary<string, AsyncExpressionFunction>

LogicalExpression

public LogicalExpression? LogicalExpression { get; protected set; }

Property Value

LogicalExpression

LogicalExpressionCache

protected ILogicalExpressionCache LogicalExpressionCache { get; }

Property Value

ILogicalExpressionCache

LogicalExpressionFactory

protected ILogicalExpressionFactory LogicalExpressionFactory { get; }

Property Value

ILogicalExpressionFactory

Options

Options for the expression evaluation.

public ExpressionOptions Options { get; set; }

Property Value

ExpressionOptions

Parameters

Parameters for the expression evaluation.

public IDictionary<string, object?> Parameters { get; set; }

Property Value

IDictionary<string, object>

Methods

EvaluateAsync()

Asynchronous evaluate the expression and return the Task.

public Task<object?> EvaluateAsync()

Returns

Task<object>

The result of the evaluation.

GetParametersNames()

Returns a list with all parameters names from the expression.

public List<string> GetParametersNames()

Returns

List<string>

HasErrors()

Create the LogicalExpression in order to check syntax errors. If errors are detected, the Error property contains the exception.

public bool HasErrors()

Returns

bool

True if the expression syntax is correct, otherwise False.

Events

EvaluateFunctionAsync

Event triggered to handle function evaluation.

public event AsyncEvaluateFunctionHandler EvaluateFunctionAsync

Event Type

AsyncEvaluateFunctionHandler

EvaluateParameterAsync

Event triggered to handle parameter evaluation.

public event AsyncEvaluateParameterHandler EvaluateParameterAsync

Event Type

AsyncEvaluateParameterHandler