Skip to content
Auto
Products

ExpressionParser

Namespace: TagBites.Expressions
Assembly: TagBites.Expressions.dll
Product: TagBites.Expressions v. 1.5.0

Parses C# expressions into LambdaExpression trees, and compiles or evaluates them.

public static class ExpressionParser

Inheritance: object → ExpressionParser

Compile<TDelegate>(string, ExpressionParserOptions)

Section titled “Compile<TDelegate>(string, ExpressionParserOptions)”

Parses an expression and compiles it into a delegate of type TDelegate.

public static TDelegate Compile(string expressionText, ExpressionParserOptions options)
  • TDelegate
    The delegate type that matches the parameters and result of the expression.
  • expressionText string
    The expression to compile.
  • options ExpressionParserOptions
    The options that control parsing and binding, or null for the defaults.

TDelegate

The compiled delegate.

DetectIdentifiers(string, ExpressionParserOptions)

Section titled “DetectIdentifiers(string, ExpressionParserOptions)”

Detects the identifiers used in an expression, without compiling it.

public static (IList<string>, IList<string>) DetectIdentifiers(string expressionText, ExpressionParserOptions options)
  • expressionText string
    The expression to inspect.
  • options ExpressionParserOptions
    The options that control parsing and binding, or null for the defaults.

(IList<string>, IList<string>)

A tuple with all identifiers found and the subset that does not resolve to a known parameter, variable, global member or type.

Parses, compiles and runs an expression, using arguments as its parameters.

public static object Invoke(string expressionText, IList<ExpressionArgument> arguments)
  • expressionText string
    The expression to evaluate.
  • arguments IList<ExpressionArgument>
    The parameters passed to the expression, matched by name.

object

The result of the expression, or null.

Invoke<T>(string, IList<ExpressionArgument>)

Section titled “Invoke<T>(string, IList<ExpressionArgument>)”

Parses, compiles and runs an expression, using arguments as its parameters, and casts the result to T.

public static T Invoke(string expressionText, IList<ExpressionArgument> arguments)
  • T
    The expected result type.
  • expressionText string
    The expression to evaluate.
  • arguments IList<ExpressionArgument>
    The parameters passed to the expression, matched by name.

T

The result of the expression cast to T, or null.

Invoke(string, ExpressionParserOptions, object[])

Section titled “Invoke(string, ExpressionParserOptions, object[])”

Parses, compiles and runs an expression, using options for binding and arguments as its parameter values.

public static object Invoke(string expressionText, ExpressionParserOptions options, object[] arguments)

object

The result of the expression, or null.

Invoke<T>(string, ExpressionParserOptions, object[])

Section titled “Invoke<T>(string, ExpressionParserOptions, object[])”

Parses, compiles and runs an expression, using options for binding and arguments as its parameter values, and casts the result to T.

public static T Invoke(string expressionText, ExpressionParserOptions options, object[] arguments)
  • T
    The expected result type.

T

The result of the expression cast to T, or null.

Parses an expression into a LambdaExpression.

public static LambdaExpression Parse(string expressionText, ExpressionParserOptions options)
  • expressionText string
    The expression to parse.
  • options ExpressionParserOptions
    The options that control parsing and binding, or null for the defaults.

LambdaExpression

The parsed lambda expression.

TryCompile<TDelegate>(string, ExpressionParserOptions, out TDelegate, out string)

Section titled “TryCompile<TDelegate>(string, ExpressionParserOptions, out TDelegate, out string)”

Tries to parse an expression and compile it into a delegate of type TDelegate.

public static bool TryCompile(string expressionText, ExpressionParserOptions options, out TDelegate function, out string errorMessage)
  • TDelegate
    The delegate type that matches the parameters and result of the expression.
  • expressionText string
    The expression to compile.
  • options ExpressionParserOptions
    The options that control parsing and binding, or null for the defaults.
  • function out TDelegate
    When this method returns, the compiled delegate, or null on failure.
  • errorMessage out string
    When this method returns, the error message, or null on success.

bool

true if the expression was compiled; otherwise, false.

TryParse(string, ExpressionParserOptions, out LambdaExpression, out string)

Section titled “TryParse(string, ExpressionParserOptions, out LambdaExpression, out string)”

Tries to parse an expression into a LambdaExpression.

public static bool TryParse(string expressionText, ExpressionParserOptions options, out LambdaExpression expression, out string errorMessage)
  • expressionText string
    The expression to parse.
  • options ExpressionParserOptions
    The options that control parsing and binding, or null for the defaults.
  • expression out LambdaExpression
    When this method returns, the parsed lambda expression, or null on failure.
  • errorMessage out string
    When this method returns, the error message, or null on success.

bool

true if the expression was parsed; otherwise, false.