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

[BUG] Constructor detection on deserialization only works when all ctor arguments are of simple type #1761

Closed
lbnascimento opened this issue Jul 22, 2020 · 0 comments
Labels

Comments

@lbnascimento
Copy link
Collaborator

lbnascimento commented Jul 22, 2020

Version
LiteDB v5.0.8, .NET Core 3.1

Describe the bug
Constructor detection on deserialization only works when all the arguments in the ctor are of a simple type (more specifically, of a type present in the Reflection.ConvertType dictionary).

In the example below, if the DateTimeOffset parameter is removed, the code works as expected.

Code to Reproduce

[Fact]
public void Custom_Ctor_Non_Simple_Types()
{
    var doc = new BsonDocument { ["_id"] = 1, ["Name"] = "myName", ["DateTimeOffset"] = new DateTime(2020, 01, 01).ToUniversalTime() };
    var obj = _mapper.ToObject<MyClass>(doc);

    obj.Id.Should().Be(1);
    obj.Name.Should().Be("myName");
    obj.DateTimeOffset.Should().Be(new DateTimeOffset(new DateTime(2020, 01, 01)));
}

Expected behavior
Deserialization with custom ctor working for any parameter type.

Additional context
This is very important for compatibility with C# 9 positional records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant