简体   繁体   English

System.Linq.Dynamic-ParseException:语法错误

[英]System.Linq.Dynamic - ParseException: syntax error

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. 执行此操作时,将引发ParseException类型的异常。 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. 编辑:我也曾尝试从MyString删除\\\\,但没有例外。

Can somebody please share some ideas? 有人可以分享一些想法吗?

Looks like you can write: 看起来你可以写:

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

Here's the tokenization code from System.Linq.Dynamic source code: 这是System.Linq.Dynamic源代码中的标记化代码:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM