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

Add a BsonClassMap method that registers a class map only if it has not already been registered

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • 2.19.0
    • Affects Version/s: None
    • Component/s: None
    • None

      The 3 RegisterClassMap methods in BsonClassMap are meant to only be called once for a given type. Normally we expect an application to know whether or not serialization has already been configured or not, but there are potential scenarios where conditional registration might be useful (such as multiple dependencies sharing some common data models where you don't have control over which dependency gets initialized first).

      It would be helpful to have a method that can be safely called without knowing in advance whether a class map for a given type has already been registered or not.

      This method could be something like:

      public void RegisterClassMapIfNotRegistered<TClass>(Action<BconClassMap<TClass>> classMapInitializer)
      

      A possible alternative is to use the `TryXyz` pattern:

      public bool TryRegisterClassMap<TClass>(Action<BsonClassMap<TClass>> classMapInitializer, out BsonClassMap<TClass> classMap)
      

      But the question is whether the `bool` return value or the `out classMap` parameter add any usefulness.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: