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 ExpressionParserInheritance: object → ExpressionParser
Methods
Section titled “Methods”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)Type Parameters
Section titled “Type Parameters”TDelegate
The delegate type that matches the parameters and result of the expression.
Parameters
Section titled “Parameters”expressionTextstring
The expression to compile.optionsExpressionParserOptions
The options that control parsing and binding, ornullfor the defaults.
Returns
Section titled “Returns”TDelegate
The compiled delegate.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
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)Parameters
Section titled “Parameters”expressionTextstring
The expression to inspect.optionsExpressionParserOptions
The options that control parsing and binding, ornullfor the defaults.
Returns
Section titled “Returns”(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.
Invoke(string, IList<ExpressionArgument>)
Section titled “Invoke(string, IList<ExpressionArgument>)”Parses, compiles and runs an expression, using arguments as its parameters.
public static object Invoke(string expressionText, IList<ExpressionArgument> arguments)Parameters
Section titled “Parameters”expressionTextstring
The expression to evaluate.argumentsIList<ExpressionArgument>
The parameters passed to the expression, matched by name.
Returns
Section titled “Returns”The result of the expression, or null.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
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)Type Parameters
Section titled “Type Parameters”T
The expected result type.
Parameters
Section titled “Parameters”expressionTextstring
The expression to evaluate.argumentsIList<ExpressionArgument>
The parameters passed to the expression, matched by name.
Returns
Section titled “Returns”T
The result of the expression cast to T, or null.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
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)Parameters
Section titled “Parameters”expressionTextstring
The expression to evaluate.optionsExpressionParserOptions
The options that control parsing and binding.argumentsobject[]
The parameter values, in the order of ExpressionParserOptions.Parameters.
Returns
Section titled “Returns”The result of the expression, or null.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
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)Type Parameters
Section titled “Type Parameters”T
The expected result type.
Parameters
Section titled “Parameters”expressionTextstring
The expression to evaluate.optionsExpressionParserOptions
The options that control parsing and binding.argumentsobject[]
The parameter values, in the order of ExpressionParserOptions.Parameters.
Returns
Section titled “Returns”T
The result of the expression cast to T, or null.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
Parse(string, ExpressionParserOptions)
Section titled “Parse(string, ExpressionParserOptions)”Parses an expression into a LambdaExpression.
public static LambdaExpression Parse(string expressionText, ExpressionParserOptions options)Parameters
Section titled “Parameters”expressionTextstring
The expression to parse.optionsExpressionParserOptions
The options that control parsing and binding, ornullfor the defaults.
Returns
Section titled “Returns”The parsed lambda expression.
Exceptions
Section titled “Exceptions”- ExpressionParserException - The expression cannot be parsed or bound.
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)Type Parameters
Section titled “Type Parameters”TDelegate
The delegate type that matches the parameters and result of the expression.
Parameters
Section titled “Parameters”expressionTextstring
The expression to compile.optionsExpressionParserOptions
The options that control parsing and binding, ornullfor the defaults.functionout TDelegate
When this method returns, the compiled delegate, ornullon failure.errorMessageout string
When this method returns, the error message, ornullon success.
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”expressionTextstring
The expression to parse.optionsExpressionParserOptions
The options that control parsing and binding, ornullfor the defaults.expressionout LambdaExpression
When this method returns, the parsed lambda expression, ornullon failure.errorMessageout string
When this method returns, the error message, ornullon success.
Returns
Section titled “Returns”true if the expression was parsed; otherwise, false.