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

Make EnumRepresentationConvention also affect collections of Enums

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.0
    • Affects Version/s: None
    • Component/s: Serialization
    • None
    • Minor Change
    • Needed
    • Hide

      `EnumRepresentationConvention` now has a new constructor: `EnumRepresentationConvention(BsonType representation, bool topLevelOnly)`.

      If `topLevelOnly` is true, the convention will work as it does now and the convention will be applied only to enum properties. If it is false, then the enum convention will be applied also to all properties that are collections of enums (lists, arrays, dictionaries, ....)

      The default value for `topLevelOnly` is true

      Show
      `EnumRepresentationConvention` now has a new constructor: `EnumRepresentationConvention(BsonType representation, bool topLevelOnly)`. If `topLevelOnly` is true, the convention will work as it does now and the convention will be applied only to enum properties. If it is false, then the enum convention will be applied also to all properties that are collections of enums (lists, arrays, dictionaries, ....) The default value for `topLevelOnly` is true

      As someone mentioned on SO (https://stackoverflow.com/questions/47313022/mongodb-c-sharp-driver-serializing-listenum-as-string), the following cases are currently not handled by the EnumRepresentationConvention:

      List<EnumType> { get; set; }
      List<List<List<EnumType>>> { get; set; }
      Dictionary<EnumType, OtherType> { get; set; }
      Dictionary<OtherType, EnumType> { get; set; }
      

      The convention currently only works on straight Enums as in

      EnumType E { get; set; }
      

      and nullable Enums as in:

      EnumType? E { get; set; }
      

      This improvement is about making sure that (even nested) collections of the various kinds are affected by the convention as expected.

            Assignee:
            ferdinando.papale@mongodb.com Ferdinando Papale
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            6 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: