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] Arrays don't work when using custom constructors #2385

Open
athendrix opened this issue Nov 10, 2023 · 1 comment
Open

[BUG] Arrays don't work when using custom constructors #2385

athendrix opened this issue Nov 10, 2023 · 1 comment
Labels

Comments

@athendrix
Copy link
Contributor

athendrix commented Nov 10, 2023

Version
5.0.17/Fedora Linux/.NET 6.0

Describe the bug
Arrays don't work when using custom constructors

Code to Reproduce

public class MultiCtorWithArray
        {
            public int Id { get; set; }
            public string[] StrArr { get; set; }
            public string Name { get; set; }
            public string DefinedOnlyInStrArray { get; set; }

            public MultiCtorWithArray()
            {
            }

            [BsonCtor]
            public MultiCtorWithArray(int id, string[] strarr)
            {
                this.Id = id;
                this.StrArr = strarr;
                this.DefinedOnlyInStrArray = "changed";
            }

            public MultiCtorWithArray(int id, string[] strarr, string name)
            {
                this.Id     = id;
                this.StrArr = strarr;
                this.Name   = name;
            }
        }
        [Fact]
        public void BsonCtorWithArray_Attribute()
        {
            var doc = new BsonDocument { ["_id"] = 25, ["name"] = "value-name", ["strarr"] = new BsonArray() {"foo","bar"} };

            var obj = _mapper.ToObject<MultiCtorWithArray>(doc);

            obj.Id.Should().Be(25);
            obj.Name.Should().Be("value-name");
            string.Join(", ", obj.StrArr).Should().Be("foo, bar");
            obj.DefinedOnlyInStrArray.Should().Be("changed");
        }

Expected behavior
This test (based off the BsonCtor_Attribute test) should pass, but it fails.

@athendrix
Copy link
Contributor Author

Fixed by pull request #2384

mbdavid added a commit that referenced this issue Nov 29, 2023
Bugfix for #2385 Also adds full record support by fixing this bug.
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