Flee icon indicating copy to clipboard operation
Flee copied to clipboard

Variable name with Non Alpha-numeric

Open ffernandezcast opened this issue 6 years ago • 3 comments

I have a scenario like. var context = new ExpressionContext(); context.Variables["FieldSet1.Q1"] = 1; context.Variables["FieldSet1.Q2"] = 2; var expression = context.CompileDynamic("FieldSet1.Field1 + FieldSet1.Field2");

In this case. Is there an option to avoid parsing evaluation over the variables names because the expression is invalid and the message returned is:

IdentifierElement: Could not find a field/property/variable with the name 'FieldSet1'

Even the validation returned just a part of the variable: "FieldSet1"

Makes sense?

ffernandezcast avatar Mar 07 '18 19:03 ffernandezcast

You can use wiki for this.

mparlak avatar Mar 10 '18 19:03 mparlak

@mparlak I can't see this info over the wiki page. If you create a variable with a . or - and so on the expression is invalid.

ffernandezcast avatar Mar 11 '18 16:03 ffernandezcast

@ffernandezcast you can use this.

Type type = typeof(FieldSet1);

ExpressionContext context = new ExpressionContext(); context.Options.ParseCulture = CultureInfo.InvariantCulture; context.ParserOptions.DecimalSeparator = '.'; context.Imports.AddType(type); context.Variables[type.Name] = fieldSet1;

IDynamicExpression compiledExpression = context.CompileDynamic("FieldSet1.Field1 + ieldSet1.Field2"); var result = compiledExpression.Evaluate();

mparlak avatar Apr 17 '18 08:04 mparlak