0

I am trying to do a string literal check using Flee, but I cannot get it to work, when I specify the string value I am trying to check it attempts to use a variable instead. Here's ny code:

var context = new ExpressionContext();
context.Variables.DefineVariable("User", typeof(User));

const string exp = @"(User.UserName = JWilly)";

var expression = context.CompileDynamic(exp);

var user = new User
{
    Id = 1,
    UserName = "JWilly",
    Active = false, 
};

context.Variables["User"] = user;

var result = expression.Evaluate();
John
  • 263
  • 1
  • 15

1 Answers1

0

A string literal is a string literal even when embedded in another string literal. Hence:

 const string exp = @"(User.UserName = ""JWilly"")";

will work. (Note the double quotation marks in conjunction with @.)

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90