Using string literal comparison using flee

813 Views Asked by At

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();
1

There are 1 best solutions below

0
Ondrej Tucny On BEST ANSWER

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 @.)