-
Type: New Feature
-
Resolution: Unresolved
-
Priority: 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()`