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

Support overriden properties with covariant return type

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Unknown Unknown
    • None
    • None
    • None

    Description

      C# 9 introduced return type covariance, and that allows us to override properties with more specific types. MongoDB's driver can't serialize such properties at the moment.

      Example:

      {}

      public class Entity
      {
          public virtual object SomeProperty { get; set; }
      }
      

      {{And:}}
      {}

      public class User : Entity
      {
          public override string SomeProperty { get; set; }
      }
      

      {{The Mongo BSON serializer thinks these are two separate properties, and it throws an exception because there are two properties that map to the same element.}}

       

      (BTW, I'm new here so if I did something wrong with this feature request please let me know){}

       

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            gur@kissterra.com Gur Galler
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: