Table of Contents

Class Expression

Namespace
NCalc
Assembly
NCalc.Sync.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 Expression : ExpressionBase<ExpressionContext>
Inheritance
Expression
Inherited Members

Constructors

Expression(LogicalExpression)

public Expression(LogicalExpression logicalExpression)

Parameters

logicalExpression LogicalExpression

Expression(LogicalExpression, ExpressionContext?)

public Expression(LogicalExpression logicalExpression, ExpressionContext? context = null)

Parameters

logicalExpression LogicalExpression
context ExpressionContext

Expression(LogicalExpression, ExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IEvaluationService)

public Expression(LogicalExpression logicalExpression, ExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IEvaluationService evaluationService)

Parameters

logicalExpression LogicalExpression
context ExpressionContext
factory ILogicalExpressionFactory
cache ILogicalExpressionCache
evaluationService IEvaluationService

Expression(LogicalExpression, ExpressionOptions, CultureInfo?)

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

Parameters

logicalExpression LogicalExpression
options ExpressionOptions
cultureInfo CultureInfo

Expression(string?)

public Expression(string? expression)

Parameters

expression string

Expression(string?, ExpressionContext?)

public Expression(string? expression, ExpressionContext? context = null)

Parameters

expression string
context ExpressionContext

Expression(string, ExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IEvaluationService)

public Expression(string expression, ExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IEvaluationService evaluationService)

Parameters

expression string
context ExpressionContext
factory ILogicalExpressionFactory
cache ILogicalExpressionCache
evaluationService IEvaluationService

Expression(string?, ExpressionOptions, CultureInfo?)

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

Parameters

expression string
options ExpressionOptions
cultureInfo CultureInfo

Properties

DynamicParameters

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

Property Value

IDictionary<string, ExpressionParameter>

EvaluationService

protected IEvaluationService EvaluationService { get; }

Property Value

IEvaluationService

Functions

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

Property Value

IDictionary<string, ExpressionFunction>

Methods

Evaluate()

Evaluates the logical expression.

public object? Evaluate()

Returns

object

The result of the evaluation.

Exceptions

NCalcException

Thrown when there is an error in the expression.

ToLambda<TResult>()

public Func<TResult> ToLambda<TResult>()

Returns

Func<TResult>

Type Parameters

TResult

ToLambda<TContext, TResult>()

public Func<TContext, TResult> ToLambda<TContext, TResult>()

Returns

Func<TContext, TResult>

Type Parameters

TContext
TResult

ToLinqExpression<TResult>()

protected virtual Expression ToLinqExpression<TResult>()

Returns

Expression

Type Parameters

TResult

ToLinqExpression<TContext, TResult>()

protected virtual Expression.LinqExpressionWithParameter ToLinqExpression<TContext, TResult>()

Returns

Expression.LinqExpressionWithParameter

Type Parameters

TContext
TResult

Events

EvaluateFunction

Event triggered to handle function evaluation.

public event EvaluateFunctionHandler EvaluateFunction

Event Type

EvaluateFunctionHandler

EvaluateParameter

Event triggered to handle parameter evaluation.

public event EvaluateParameterHandler EvaluateParameter

Event Type

EvaluateParameterHandler