System.Linq.Dynamic - ParseException: syntax error

c# dynamic-linq expression

Question

I have the following code:

class Program
{
    public class Test
    {
        public string Property { get; set; }
    }
    static void Main(string[] args)
    {
        var expressionString = "Property == \"MySt\\\"ring\"";
        var p = System.Linq.Expressions.Expression.Parameter(typeof(Test));
        var e = System.Linq.Dynamic.DynamicExpression.ParseLambda(new[] { p }, null, expressionString);
    }
}

On executing this, an exception of type ParseException is thrown. The requirement is to have a string literal with a quote in between.

Edit: I have also tried removing \\ from MyString with no change in exception.

Can somebody please share some ideas?

1
1
7/3/2014 9:10:59 AM

Accepted Answer

Looks like you can write:

"Property == \"MySt\"\"ring\""

Here's the tokenization code from System.Linq.Dynamic source code:

case '"':
case '\'':
    char quote = ch;
    do {
        NextChar();
        while (textPos < textLen && ch != quote) NextChar();
        if (textPos == textLen)
            throw ParseError(textPos, Res.UnterminatedStringLiteral);
        NextChar();
    } while (ch == quote);
    t = TokenId.StringLiteral;
    break;
2
7/3/2014 9:22:41 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow