Skip to content

Commit

Permalink
Merge 09df1f3 into f5a749a
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo authored Jul 6, 2020
2 parents f5a749a + 09df1f3 commit 0af290d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ IAllowedMemberValues Register(IServiceProvider arg)
.ToDictionary(x => x.Key, x => (ISpecification<object>)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<MemberInfo, IAllowedValueSpecification>(_allowed);
Expand Down
8 changes: 8 additions & 0 deletions src/ExtendedXmlSerializer/ExtensionModel/Defaults.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using ExtendedXmlSerializer.ExtensionModel.References;
using ExtendedXmlSerializer.ReflectionModel;
using System.Reflection;

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);
}
}
Original file line number Diff line number Diff line change
@@ -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<TypeInfo, ContentModel.ISerializer>, 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<TypeInfo> comparer) : base(comparer) {}
}
Expand Down
45 changes: 45 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue411Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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<SubjectBase>()
.Member(x => x.Message)
.EmitWhen(x => false)
.Create()
.ForTesting();

serializer.Cycle(new Subject {Message = "Hello World!"}).Message.Should().BeNull();
}


[Fact]
public void VerifyInstance()
{
var serializer = new ConfigurationContainer().Type<SubjectBase>()
.Member(x => x.Message)
.EmitWhenInstance(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; }
}
}
}

0 comments on commit 0af290d

Please sign in to comment.