Class CompilingExpressionEvaluator<TContext, TResult, TArg>
Implements an evaluator that compiles all expressions represented by instances of this class in a certain scope into dynamic assemblies. Every unique scope name creates a separate assembly. The compilation of scope is triggered either by a call to Compile() or first attempt to call Evaluate() on any instance within a scope. Once a scope has been compiled, no further allocations in this scoped are allowed, this is because CLR does not allow to unload assemblies dynamically. Within an expression context is passed as "ctx" and argument as "arg". This class is thread-safe.
Inheritance
Inherited Members
Namespace: Azos.Text
Assembly: Azos.dll
Syntax
public class CompilingExpressionEvaluator<TContext, TResult, TArg>
Type Parameters
Name | Description |
---|---|
TContext | |
TResult | |
TArg |
Constructors
CompilingExpressionEvaluator(String, String, IEnumerable<String>, IEnumerable<String>)
Allocates a new expression. This call fails if the scope was already compiled
Declaration
public CompilingExpressionEvaluator(string scope, string expression, IEnumerable<string> referencedAssemblies = null, IEnumerable<string> usings = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | scope | A valid identifier for namespace sub-path like "mycode.test" no leading or trailing "." |
System.String | expression | A C# expression to compile |
System.Collections.Generic.IEnumerable<System.String> | referencedAssemblies | An enumerable of assemblies that compiler should reference while building scope assembly i.e. "MyCompany.dll" |
System.Collections.Generic.IEnumerable<System.String> | usings | Extra usings i.e. "System.IO", "MyCode.Routines" etc. |
Properties
Expression
Returns an original expression as string that is to be evaluated
Declaration
public string Expression { get; }
Property Value
Type | Description |
---|---|
System.String |
Scope
Returns a scope (similar to compilation unit / assembly) that this expression is in
Declaration
public string Scope { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
Compile()
Forces the entire scope compilation now, so no delay is incurred on first call to Evaluate().
Declaration
public void Compile()
Evaluate(TContext, TArg)
Evaluates expression using supplied arg in a context. Context is passed as "ctx" and argument as "arg".
Declaration
public TResult Evaluate(TContext context, TArg arg)
Parameters
Type | Name | Description |
---|---|---|
TContext | context | |
TArg | arg |
Returns
Type | Description |
---|---|
TResult |
IsScopeAlreadyCompiled(String)
Indicates whether this scope has already been compiled and no more epressions can be allocated in it
Declaration
public static bool IsScopeAlreadyCompiled(string scope)
Parameters
Type | Name | Description |
---|---|---|
System.String | scope |
Returns
Type | Description |
---|---|
System.Boolean |