Table of Contents

Class DynamicExpression<TCtx, TRes>

Namespace
Tlabs.Dynamic
Assembly
Tlabs.Core.dll

Objects of this class represent dynamically compiled expressions to be evaluated by calling the delegate provided by the Evaluate property.

public class DynamicExpression<TCtx, TRes>

Type Parameters

TCtx

The expression's context data type.

Each public property of this type is going to be accessible by its property name in the direct scope of the expression. An object type like:

new { Name= "abc", Value= 123 }
would make its properties 'Name' and 'Value' accessible for a expression
"Name != "xyz" and Value > 100"
.
TRes

The expression's result type.

This must be the type that the given expression results to, i.e. a comparision expression like
"Value == 123"
would have the result type bool.
Inheritance
DynamicExpression<TCtx, TRes>
Inherited Members
Extension Methods

Constructors

DynamicExpression(string, IReadOnlyDictionary<string, Type>?, IReadOnlyDictionary<string, object>?)

Ctor from expression and ctxConverter

public DynamicExpression(string expression, IReadOnlyDictionary<string, Type>? ctxConverter = null, IReadOnlyDictionary<string, object>? funcLib = null)

Parameters

expression string
ctxConverter IReadOnlyDictionary<string, Type>
funcLib IReadOnlyDictionary<string, object>

Remarks

In case any of the TCtx's properties should give an object of a dynamically created type (like with CreateType(IList<DynamicProperty>, Type?, string?)):

The property exposed to the expression scope will now get the actual dynamic type given by the ctxConverter.

Properties

Evaluate

Delegate to be called to evaluate the expression.

public Func<TCtx, TRes> Evaluate { get; }

Property Value

Func<TCtx, TRes>

Examples

var expr = new DynamicExpression<MyContextType, bool>("Value > 100");
bool result = expr.Evaluate(myContextObject);

Source

Expression source.

public string Source { get; }

Property Value

string