Skip to content

Commit

Permalink
Merge 1748f6c into 7ca827a
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo committed Aug 25, 2021
2 parents 7ca827a + 1748f6c commit 6f7ad6e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using ExtendedXmlSerializer.Core.Sources;
using System;

namespace ExtendedXmlSerializer.ContentModel.Format
{
sealed class FormattedContent<T> : IFormattedContent<T>
{
readonly Func<IFormatWriter, IFormatter<T>> _source;

public FormattedContent(Func<IFormatWriter, IFormatter<T>> source)
{
_source = source;
}
public FormattedContent(Func<IFormatWriter, IFormatter<T>> source) => _source = source;

public string Get(IFormatWriter writer, T instance) => _source(writer)
.Get(instance);
public string Get(IFormatWriter writer, T instance) => _source(writer).Get(instance);
}
}
23 changes: 12 additions & 11 deletions src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

// ReSharper disable TooManyDependencies

namespace ExtendedXmlSerializer.ExtensionModel.Xml
Expand Down Expand Up @@ -55,6 +56,13 @@ public void Start(IIdentity identity)
var identifier = identity.Identifier.NullIfEmpty();
if (identifier != null)
{
switch (Count)
{
case 0:
Add(string.Empty, identifier);
break;
}

_writer.WriteStartElement(identity.Name, identifier);
}
else
Expand Down Expand Up @@ -115,16 +123,9 @@ public void Dispose()
string Prefix(string parameter) => Lookup(parameter) ?? CreatePrefix(parameter);

string Lookup(string parameter)
{
var lookup = _prefixes.Get(parameter);
if (parameter != null && lookup == string.Empty && !ContainsKey(string.Empty))
{
Add(string.Empty, parameter);
}

var result = parameter == this.Get(string.Empty) || parameter == null ? string.Empty : lookup;
return result;
}
=> parameter != null
? parameter == this.Get(string.Empty) ? string.Empty : _prefixes.Get(parameter)
: string.Empty;

string CreatePrefix(string identifier)
{
Expand All @@ -140,7 +141,7 @@ string CreatePrefix(string identifier)

string Create(string parameter)
{
var result = _formatter.Get(Count + 1);
var result = _formatter.Get(Count);
Add(result, parameter);
return result;
}
Expand Down
43 changes: 43 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue528Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using System.Collections.Generic;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue528Tests
{
[Fact]
public void Verify()
{
var instance = new ClassWithDictionary();
instance.Dict.Add("key",123);

var configuration = new ConfigurationContainer();
var serializer = configuration.Create().ForTesting();
serializer.Cycle(instance).Should().BeEquivalentTo(instance);
}

public class ClassWithDictionary
{
public ClassWithDictionary()
{
Dict = new Dictionary<string, object>();

ListWithItems = new List<ClassWithProperty>();
ListWithItems.Add(new ClassWithProperty());
}

public Dictionary<string,object> Dict { get; set; }

public IList<ClassWithProperty> ListWithItems { get; set; }
}

public class ClassWithProperty
{
public string Text { get; set; }
}

}
}

0 comments on commit 6f7ad6e

Please sign in to comment.