Skip to content

Commit

Permalink
Merge ff26643 into bdc0ca5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo authored Jul 16, 2020
2 parents bdc0ca5 + ff26643 commit da6281f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System.Xml;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.ContentModel.Identification;
using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.Core.Sources;
using System.Xml;

namespace ExtendedXmlSerializer.ExtensionModel.Xml
{
sealed class FormatReaderContexts
: ReferenceCacheBase<System.Xml.XmlReader, IFormatReaderContext>,
IFormatReaderContexts
sealed class FormatReaderContexts : ReferenceCacheBase<System.Xml.XmlReader, IFormatReaderContext>,
IFormatReaderContexts
{
readonly IIdentityStore _store;
readonly IXmlParserContexts _contexts;
readonly ITypes _types;

public FormatReaderContexts(IIdentityStore store, ITypes types) :
this(store, types, XmlParserContexts.Default) {}
public FormatReaderContexts(IIdentityStore store, ITypes types)
: this(store, types, XmlParserContexts.Default) {}

public FormatReaderContexts(IIdentityStore store, ITypes types, IXmlParserContexts contexts)
{
Expand Down
29 changes: 11 additions & 18 deletions src/ExtendedXmlSerializer/ExtensionModel/Xml/MigrationsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ IContents Register(IServiceProvider services, IContents contents)

void ICommand<IServices>.Execute(IServices parameter) {}

public void Add(TypeInfo key, params Action<XElement>[] items)
{
var current = Get(key)
?.ToArray() ?? Enumerable.Empty<Action<XElement>>();
Assign(key, current.Appending(items)
.Fixed());
}

sealed class Contents : IContents
{
readonly IFormatReaders _factory;
Expand Down Expand Up @@ -76,12 +68,12 @@ sealed class Migrator : IMigrator
{
readonly static MigrationVersionIdentity Identity = MigrationVersionIdentity.Default;

readonly IFormatReaders _factory;
readonly TypeInfo _type;
readonly IClassification _classification;
readonly ImmutableArray<Action<XElement>> _migrations;
readonly uint _version;
readonly IProperty<uint> _property;
readonly IFormatReaders _factory;
readonly TypeInfo _type;
readonly IClassification _classification;
readonly ImmutableArray<Action<XElement>> _migrations;
readonly uint _version;
readonly IProperty<uint> _property;

public Migrator(IFormatReaders factory, TypeInfo type, IClassification classification,
ImmutableArray<Action<XElement>> migrations)
Expand Down Expand Up @@ -109,9 +101,8 @@ public IFormatReader Get(IFormatReader parameter)
throw new XmlException($"Unknown varsion number {version} for type {typeInfo}.");
}

var element = XElement.Load(parameter.Get()
.AsValid<System.Xml.XmlReader>()
.ReadSubtree());
var reader = parameter.Get().AsValid<System.Xml.XmlReader>();
var element = XElement.Load(reader.ReadSubtree());
for (var i = version; i < _version; i++)
{
var index = (int)i;
Expand All @@ -124,6 +115,8 @@ public IFormatReader Get(IFormatReader parameter)
}

var xmlReader = element.CreateReader();
XmlParserContexts.Default.Assign(xmlReader.NameTable,
XmlParserContexts.Default.Get(reader.NameTable));
var result = _factory.Get(xmlReader);
AssociatedReaders.Default.Assign(result, parameter);
return result;
Expand All @@ -134,7 +127,7 @@ public IFormatReader Get(IFormatReader parameter)

sealed class Serializer : ContentModel.ISerializer
{
readonly IMigrator _migrator;
readonly IMigrator _migrator;
readonly ContentModel.ISerializer _serializer;

public Serializer(IMigrator migrator, ContentModel.ISerializer serializer)
Expand Down
48 changes: 48 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue414Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue414Tests
{
[Fact]
public void Verify()
{
var serializer = new ConfigurationContainer().Type<Base>()
.AddMigration(EmptyMigration.Default)
.Create()
.ForTesting();
var container = new Container {Content = new Inherit()};
serializer.Cycle(container).Should().BeEquivalentTo(container);
}

public class Container
{
public Base Content { get; set; }
}

public class Inherit : Base {}

public class Base {}

sealed class EmptyMigration : IEnumerable<Action<XElement>>
{
public static EmptyMigration Default { get; } = new EmptyMigration();

EmptyMigration() {}

public IEnumerator<Action<XElement>> GetEnumerator()
{
yield break;
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
}

0 comments on commit da6281f

Please sign in to comment.