Click or drag to resize

TemplatedExpressionParserExecute Method

Executes replacements using provided substitutions dictionary on the currently defined TemplatedExpression value and optionally evaluates any expressions.

Namespace: GSF.Parsing
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public string Execute(
	IDictionary<string, string> substitutions,
	bool ignoreCase = true,
	bool evaluateExpressions = true,
	bool escapeSubstitutionValues = true
)
View Source

Parameters

substitutions  IDictionaryString, String
Dictionary of substitutions. Dictionary keys are tokens to be replaced by the values.
ignoreCase  Boolean  (Optional)
Determines if substitutions should be case insensitive. Defaults to true.
evaluateExpressions  Boolean  (Optional)
Determines if expressions should be evaluated. Defaults to true.
escapeSubstitutionValues  Boolean  (Optional)
Determines if reserved symbols in substitution values should be automatically escaped. Defaults to true.

Return Value

String
A string that was based on TemplatedExpression with tokens replaced and expressions evaluated.
Remarks

The default token start and end delimiters are { and } but can be overridden in TemplatedExpressionParser constructor. All substitution tokens surrounded by StartTokenDelimiter and EndTokenDelimiter (e.g., {token}) will be immediately replaced with their string equivalents before further expression evaluation. As a result of the expression syntax <, >, =, and ! are reserved expressions symbols; StartTokenDelimiter, EndTokenDelimiter, StartExpressionDelimiter and EndExpressionDelimiter are reserved delimiter symbols. To embed any reserved symbol into the TemplatedExpression so that it appears in the evaluated result, escape the symbol by prefixing it with a backslash, e.g., \{.

The default expression start and end delimiters are [ and ] but can be overridden in TemplatedExpressionParser constructor. Expressions are represented in the form of [?expression[result]] and can be nested, e.g. ([?expression1[?expression2[result]]]). Expressions should not contain extraneous white space for proper evaluation. Only simple boolean comparison operations are allowed in expressions, e.g., A=B (or A==B), A!=B (or A<>B), A>B, A>=B, A<B and A<=B - nothing more. Any expression that fails to evaluate will be evaluated as FALSE. Note that if both left (A) and right (B) operands can be parsed as a numeric value then the expression will be numerically evaluated otherwise expression will be a culture-invariant string comparison. Nested expressions are evaluated as cumulative AND operators. There is no defined nesting limit.

Advanced expressions can be parsed using the eval function, e.g., eval{1 + 2}. Eval function expression is delimited by the currently defined token delimiters, { and } by default. The evaluation engine deals with numbers and strings. The typing of numeric literals follow C# standards, suffixes such as d, f and m may be used to explicitly specify the numeric type. If no numeric suffix is provided, the default type of a numeric literal is assumed to be Int32. String literals should be specified using single quotes instead of double quotes, this includes substitution parameters, e.g., eval{'{DeviceAcronym}'.Length + 1}. Advanced evaluation expressions using the eval function are always parsed after common expressions. Eval functions cannot be nested.

When evaluateExpressions is true and values in substitutions intentionally contain expressions to be evaluated, then escapeSubstitutionValues should be set to false so that the reserved symbols in the values are not automatically escaped.

See Also