Skip to content

Culture Sensitive Expressions

Muhammet Parlak edited this page Jul 9, 2017 · 1 revision

Flee allows you to specify the culture used to parse expressions. This lets you enter expressions that use numbers in the format of a particular culture and have them be correctly parsed into an expression.

When the parse culture is set, Flee will use the CultureInfo.NumberFormat.NumberDecimalSeparator as the decimal point for real numbers and the CultureInfo.TextInfo.ListSeparator as the function argument separator.

The following example shows how to set this up:

// Set the culture of Flee's parser
CultureInfo ci = new CultureInfo("fr-FR");            

ExpressionContext context = new ExpressionContext();
context.ParseCulture = ci
context.Imports.AddType(typeof(Math));
            
// Create an expression that uses numbers in the culture's format
IDynamicExpression e = context.CompileDynamic("round(100,75; 1)");
object result = e.Evaluate();