Skip to content

Commit

Permalink
Merge 038ca82 into f726851
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo authored Sep 28, 2020
2 parents f726851 + 038ca82 commit 51572da
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
using System.Linq;
using System.Reflection;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.Core.Sources;
using JetBrains.Annotations;
using System.Linq;

namespace ExtendedXmlSerializer.ExtensionModel.References
{
sealed class ReferenceEncounters : ReferenceCacheBase<IFormatWriter, IEncounters>, IReferenceEncounters
{
readonly IRootReferences _references;
readonly IEntities _entities;
readonly ObjectIdGenerator _generator;
readonly IRootReferences _references;
readonly IEntities _entities;

[UsedImplicitly]
public ReferenceEncounters(IRootReferences references, IEntities entities)
: this(references, entities, new ObjectIdGenerator()) {}

public ReferenceEncounters(IRootReferences references, IEntities entities, ObjectIdGenerator generator)
{
_references = references;
_entities = entities;
_generator = generator;
}

protected override IEncounters Create(IFormatWriter parameter)
=> new Encounters(_references.Get(parameter)
.ToDictionary(x => x, Get));
=> new Encounters(_references.Get(parameter).ToDictionary(x => x, new Generators(_entities).Get));

sealed class Generators : StructureCacheBase<object, Identifier>
{
readonly IEntities _entities;
readonly ObjectIdGenerator _generator;

public Generators(IEntities entities) : this(entities, new ObjectIdGenerator()) {}

Identifier Get(object parameter)
=> new Identifier(_generator.For(parameter), _entities.Get(parameter.GetType()
.GetTypeInfo()));
public Generators(IEntities entities, ObjectIdGenerator generator)
{
_entities = entities;
_generator = generator;
}

protected override Identifier Create(object parameter)
=> new Identifier(_generator.For(parameter), _entities.Get(parameter.GetType()));
}
}
}
38 changes: 38 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue454Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue454Tests
{
[Fact]
public void Verify()
{
var serializer = new ConfigurationContainer().UseAutoFormatting()
.UseOptimizedNamespaces()
.EnableReferences()
.Create()
.ForTesting();

var myRef = new Foo();
var instance = new Foo
{
Ref1 = myRef,
Ref2 = myRef
};

var first = serializer.Serialize(serializer.Cycle(instance));
var second = serializer.Serialize(serializer.Cycle(instance));

first.Should().Be(second);
}

public class Foo
{
public Foo Ref1 { get; set; }
public Foo Ref2 { get; set; }
}
}
}

0 comments on commit 51572da

Please sign in to comment.