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

ImmutableTypeClassMapConvention should not consider static properties

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.9.3
    • Affects Version/s: 2.7.0
    • Component/s: Serialization
    • None
    • Fully Compatible

      Consider the following immutable class:

       

      public class C 
      {
          public C(int x)
          { 
              X = x; 
          }    
      
          public static C Default { get; } = new C(0);
       
          public int X { get; }
      }
      

       

      The ImmutableTypeClassMapConvention refuses to map such a class, because when obtaining the properties of a type, it calls the GetProperties method with no parameters. According to the MSDN documentation, both instance and static properties of a type are returned in this case. 

      The suggested fix is to consider instance properties only by setting the correct BindingFlags.

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            sergey_ro Sergey Rodyushkin
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: