Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3411

Ctors with Readonly Setters should just work.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.11.6
    • None
    • BSON
    • None
    • Windows 10 Pro

    Description

      The following simple class should be able to serialize and deserialize to the database without modification.

      public class Sample
          {
              public Sample(DateTime dateTime, double value)
              {
                  DateTime = dateTime;
                  Value = value;
              }
              
              public DayOfWeek Day => DateTime.DayOfWeek;
              public int Hour => DateTime.TimeOfDay.Hours;
       
              public DateTime DateTime { get; }
              public double Value { get; }
          }
      

      It is very clear the intent of this class. We have tried using [BsonConstructor] with no success either. We shouldn't be forced to use private setters to make this work. Private setters are very different than readonly setters, in both cases serialization and deserialization should just work.

      Attachments

        Issue Links

          Activity

            People

              dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
              tristen.fielding@gmail.com Tristen Fielding
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: