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

Ctors with Readonly Setters should just work.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.11.6
    • Fix Version/s: None
    • Component/s: Bson
    • Security Level: Public
    • Labels:
      None
    • Environment:
      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

              Assignee:
              dmitry.lukyanov Dmitry Lukyanov
              Reporter:
              tristen.fielding@gmail.com Tristen Fielding
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: