-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 2.2.4
-
Component/s: BSON, Serialization
-
None
Documentation suggests here would suggest that it's possible to map a constructor's parameters to various members by specifying them in overloads of the BsonConstructorAttribute.
As far as I can tell, this attribute has only one overload, which takes a sequence of strings. Assuming that these strings are supposed to be the names of the members to map to, this does not appear to be working as intended.
The following class will not serialise:
public class Product { public int Id { get; private set; } [BsonIgnoreIfNull] public string Name { get; private set; } [BsonIgnoreIfNull] public int OtherField { get; private set; } [BsonConstructor("Id","Name")] public Product(int id, string val) { Id = id; Name = val; } [BsonConstructor("Id","OtherField")] public Product(int id, int val) { Id = id; OtherField = val; } }
The following which follows the default naming convention does work however:
public class Product { public int Id { get; private set; } [BsonIgnoreIfNull] public string Name { get; private set; } [BsonIgnoreIfNull] public int OtherField { get; private set; } [BsonConstructor] public Product(int id, string name) { Id = id; Name = name; } [BsonConstructor] public Product(int id, int otherField) { Id = id; OtherField = otherField; } }