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

Ctors with Readonly Setters should just work.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.11.6
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      Windows 10 Pro

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

      Unable to find source-code formatter for language: cs. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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.

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

              Created:
              Updated:
              Resolved: