Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization of Expression<Func<T, bool>> #77

Closed
markjerz opened this issue Nov 2, 2017 · 0 comments · Fixed by #78
Closed

Serialization of Expression<Func<T, bool>> #77

markjerz opened this issue Nov 2, 2017 · 0 comments · Fixed by #78

Comments

@markjerz
Copy link
Contributor

markjerz commented Nov 2, 2017

I'm unable to round-trip serialization of an Expression<Func<T, bool>>.

I can see the CanSerializeLambdaExpression test within the code base that is similar but my following test case fails, the Method property (of type MethodInfo) inside the MethodCallExpression is null upon de-serialization.

Hopefully someone can help me resolve this. It might take me a while to navigate the codebase and track down the solution myself. Happy to help with a pull request if someone has an idea though.

[Fact]
public void CanSerializeStronglyTypedLambdaExpression() {
    Expression<Func<Something, bool>> expr = s => new[] { "Bar", "Car" }.Contains(s.Foo);
    var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true));
    using (var ms = new MemoryStream())
    {
        serializer.Serialize(expr, ms);
        ms.Seek(0, SeekOrigin.Begin);
        var deserialized = serializer.Deserialize<Expression<Func<Something, bool>>>(ms);
        Assert.NotNull(((MethodCallExpression)deserialized.Body).Method);
        Assert.True(expr.Parameters[0] == ((MemberExpression)(((MethodCallExpression)deserialized.Body).Arguments[1])).Expression);
        Assert.True(deserialized.Compile()(new Something { Foo = "Bar" }));
    }
}

public class Something {
    public string Foo { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants