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

Unable to create class map for combined interfaces

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • None
    • Dotnet Drivers

      Summary

      On the latest version of the master branch, if you call AutoMap on an interface then it will map properties of the interface.

      If that interface implements another interface, the properties of that second interface will not be mapped.

      How to Reproduce

      In AttributeConventionPackTests.cs add the following

              [Fact]
              public void TestOptsInInterfaceMembers()
              {
                  var convention = AttributeConventionPack.Instance;
                  var classMap = new BsonClassMap<ITestInterface>();
                  new ConventionRunner(convention).Apply(classMap);
      
                  Assert.Equal(1, classMap.DeclaredMemberMaps.Count());
                  Assert.Equal(nameof(ITestInterface.Foo), classMap.GetMemberMap(nameof(ITestInterface.Foo)).ElementName);
              }
      
              [Fact]
              public void TestOptsInCombinedInterfaceMembers()
              {
                  var convention = AttributeConventionPack.Instance;
                  var classMap = new BsonClassMap<ITestCombinedInterface>();
                  new ConventionRunner(convention).Apply(classMap);
      
                  Assert.Equal(2, classMap.DeclaredMemberMaps.Count());
                  Assert.Equal(nameof(ITestCombinedInterface.Foo), classMap.GetMemberMap(nameof(ITestCombinedInterface.Foo)).ElementName);
                  Assert.Equal(nameof(ITestCombinedInterface.Bar), classMap.GetMemberMap(nameof(ITestCombinedInterface.Bar)).ElementName);
              }
      
              private interface ITestInterface
              {
                  [BsonElement]
                  public string Foo { get; }
              }
      
              private interface ITestCombinedInterface : ITestInterface
              {
                  [BsonElement]
                  public string Bar { get; }
              }
      

      TestOptsInInterfaceMembers will pass.
      TestOptsInCombinedInterfaceMembers will fail.

      Additional Background

      This is due to `typeInfo.GetXXX` only looking for members that are defined in the specified interface. Discovering members that are defined by other interfaces requires a call to `classTypeInfo.GetInterfaces()`

            Assignee:
            Unassigned Unassigned
            Reporter:
            strue36@gmail.com Sean True
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: