我有以下代码:
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);
}
}
执行此操作时,抛出类型ParseException
的异常。要求是在字符串文字之间加上引号。
修改:我还尝试从MyString
删除\\,但异常没有变化。
有人可以分享一些想法吗?
答案 0 :(得分:2)
看起来你可以写:
"Property == \"MySt\"\"ring\""
这是来自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;