diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllowedMemberValuesExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllowedMemberValuesExtension.cs index 940f15366..d7158cfe4 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllowedMemberValuesExtension.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllowedMemberValuesExtension.cs @@ -67,7 +67,7 @@ IAllowedMemberValues Register(IServiceProvider arg) .ToDictionary(x => x.Key, x => (ISpecification)x.Value) .Concat(Instances) .GroupBy(x => x.Key) - .ToDictionary(x => x.Key, Create)), + .ToDictionary(x => x.Key, Create, Defaults.MemberComparer)), fallback = _allowed == AllowAssignedValues ? Source.Default : new FixedInstanceSource(_allowed); diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Defaults.cs b/src/ExtendedXmlSerializer/ExtensionModel/Defaults.cs index 9d53d519b..7f9dd5e0b 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Defaults.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Defaults.cs @@ -1,4 +1,5 @@ using ExtendedXmlSerializer.ExtensionModel.References; +using ExtendedXmlSerializer.ReflectionModel; using System.Reflection; namespace ExtendedXmlSerializer.ExtensionModel @@ -6,5 +7,12 @@ namespace ExtendedXmlSerializer.ExtensionModel static class Defaults { public static TypeInfo Reference { get; } = typeof(ReferenceIdentity).GetTypeInfo(); + + public static ITypeComparer TypeComparer { get; } + = new CompositeTypeComparer(ImplementedTypeComparer.Default, + TypeIdentityComparer.Default, + InheritedTypeComparer.Default); + + public static IMemberComparer MemberComparer { get; } = new MemberComparer(TypeComparer); } } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Xml/CustomSerializers.cs b/src/ExtendedXmlSerializer/ExtensionModel/Xml/CustomSerializers.cs index 09c45897d..6615c03a9 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Xml/CustomSerializers.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Xml/CustomSerializers.cs @@ -1,16 +1,11 @@ -using ExtendedXmlSerializer.ReflectionModel; -using System.Collections.Generic; +using System.Collections.Generic; using System.Reflection; namespace ExtendedXmlSerializer.ExtensionModel.Xml { sealed class CustomSerializers : Metadata, ICustomSerializers { - readonly static CompositeTypeComparer Comparer = new CompositeTypeComparer(ImplementedTypeComparer.Default, - TypeIdentityComparer.Default, - InheritedTypeComparer.Default); - - public CustomSerializers() : this(Comparer) {} + public CustomSerializers() : this(ExtensionModel.Defaults.TypeComparer) {} public CustomSerializers(IEqualityComparer comparer) : base(comparer) {} } diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue411Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue411Tests.cs new file mode 100644 index 000000000..ef09a07c6 --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue411Tests.cs @@ -0,0 +1,32 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue411Tests + { + [Fact] + public void Verify() + { + var serializer = new ConfigurationContainer().Type() + .Member(x => x.Message) + .EmitWhen(x => false) + .Create() + .ForTesting(); + + serializer.Cycle(new Subject {Message = "Hello World!"}).Message.Should().BeNull(); + } + + sealed class Subject : SubjectBase + { + public override string Message { get; set; } + } + + public abstract class SubjectBase + { + public abstract string Message { get; set; } + } + } +} \ No newline at end of file