Skip to content

Commit

Permalink
Skipped processing of parameterized-content members that have custom …
Browse files Browse the repository at this point in the history
…serializers applied.
  • Loading branch information
Mike-E-angelo committed Oct 13, 2020
1 parent d834fd9 commit 6cc226e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
using ExtendedXmlSerializer.ContentModel.Identification;
using ExtendedXmlSerializer.ContentModel.Members;
using ExtendedXmlSerializer.ExtensionModel.Xml;
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using ExtendedXmlSerializer.ContentModel.Identification;
using ExtendedXmlSerializer.ContentModel.Members;

namespace ExtendedXmlSerializer.ExtensionModel.Content.Members
{
sealed class ParameterizedTypeMembers : ITypeMembers
{
readonly ITypeMembers _typed;
readonly IParameterizedMembers _members;
readonly ITypeMembers _previous;
readonly IContainsCustomSerialization _custom;
readonly IParameterizedMembers _members;
readonly Func<IMember, string> _group;

public ParameterizedTypeMembers(ITypeMembers previous, IContainsCustomSerialization custom,
IParameterizedMembers members)
: this(previous, custom, members, IdentityFormatter.Default.Get) {}

public ParameterizedTypeMembers(ITypeMembers typed, IParameterizedMembers members)
// ReSharper disable once TooManyDependencies
public ParameterizedTypeMembers(ITypeMembers previous, IContainsCustomSerialization custom,
IParameterizedMembers members, Func<IMember, string> group)
{
_typed = typed;
_members = members;
_previous = previous;
_custom = custom;
_members = members;
_group = @group;
}

public ImmutableArray<IMember> Get(TypeInfo parameter)
=> _custom.IsSatisfiedBy(parameter) ? ImmutableArray<IMember>.Empty : Implementation(parameter);

ImmutableArray<IMember> Implementation(TypeInfo parameter)
{
var members = _members.Get(parameter);
var typed = _typed.Get(parameter);
var typed = _previous.Get(parameter);
var items = members?.AddRange(typed) ?? typed;

var result = items.GroupBy(IdentityFormatter.Default.Get)
var result = items.GroupBy(_group)
.Select(x => x.OfType<ParameterizedMember>()
.FirstOrDefault() ?? x.First())
.ToImmutableArray();
Expand Down
53 changes: 53 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue458Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.ContentModel;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using System;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue458Tests
{
[Fact]
public void Verify()
{
var instance = new DecoratedImage(null);

var serializer = new ConfigurationContainer().EnableParameterizedContentWithPropertyAssignments()
.UseOptimizedNamespaces()
//
.Type<DecoratedImage>()
.Register()
.Serializer()
.Of<ImageSerializer>()
//
.Create()
.ForTesting();

serializer.Assert(instance, @"<?xml version=""1.0"" encoding=""utf-8""?><Issue458Tests-DecoratedImage xmlns=""clr-namespace:ExtendedXmlSerializer.Tests.ReportedIssues;assembly=ExtendedXmlSerializer.Tests.ReportedIssues"" />");
}

public class ImageSerializer : ISerializer<DecoratedImage>
{
public DecoratedImage Get(IFormatReader parameter) => new DecoratedImage(null);

public void Write(IFormatWriter writer, DecoratedImage instance) {}
}

public class DecoratedImage
{
public DecoratedImage(Metadata metadata) => Metadata = metadata;

public Metadata Metadata
{
// ReSharper disable once ThrowExceptionInUnexpectedLocation
get => throw new NotImplementedException();
// ReSharper disable once RedundantAssignment
set => value = null;
}
}

public class Metadata {}
}
}

0 comments on commit 6cc226e

Please sign in to comment.