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
LogicalExpressioncontext
ExpressionContext
Expression(LogicalExpression, ExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IEvaluationService)
public Expression(LogicalExpression logicalExpression, ExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IEvaluationService evaluationService)
Parameters
logicalExpression
LogicalExpressioncontext
ExpressionContextfactory
ILogicalExpressionFactorycache
ILogicalExpressionCacheevaluationService
IEvaluationService
Expression(LogicalExpression, ExpressionOptions, CultureInfo?)
public Expression(LogicalExpression logicalExpression, ExpressionOptions options = ExpressionOptions.None, CultureInfo? cultureInfo = null)
Parameters
logicalExpression
LogicalExpressionoptions
ExpressionOptionscultureInfo
CultureInfo
Expression(string?)
public Expression(string? expression)
Parameters
expression
string
Expression(string?, ExpressionContext?)
public Expression(string? expression, ExpressionContext? context = null)
Parameters
expression
stringcontext
ExpressionContext
Expression(string, ExpressionContext, ILogicalExpressionFactory, ILogicalExpressionCache, IEvaluationService)
public Expression(string expression, ExpressionContext context, ILogicalExpressionFactory factory, ILogicalExpressionCache cache, IEvaluationService evaluationService)
Parameters
expression
stringcontext
ExpressionContextfactory
ILogicalExpressionFactorycache
ILogicalExpressionCacheevaluationService
IEvaluationService
Expression(string?, ExpressionOptions, CultureInfo?)
public Expression(string? expression, ExpressionOptions options = ExpressionOptions.None, CultureInfo? cultureInfo = null)
Parameters
expression
stringoptions
ExpressionOptionscultureInfo
CultureInfo
Properties
DynamicParameters
public IDictionary<string, ExpressionParameter> DynamicParameters { get; set; }
Property Value
EvaluationService
protected IEvaluationService EvaluationService { get; }
Property Value
Functions
public IDictionary<string, ExpressionFunction> Functions { get; set; }
Property Value
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
Type Parameters
TResult
ToLinqExpression<TContext, TResult>()
protected virtual Expression.LinqExpressionWithParameter ToLinqExpression<TContext, TResult>()
Returns
Type Parameters
TContext
TResult
Events
EvaluateFunction
Event triggered to handle function evaluation.
public event EvaluateFunctionHandler EvaluateFunction
Event Type
EvaluateParameter
Event triggered to handle parameter evaluation.
public event EvaluateParameterHandler EvaluateParameter