Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed attribute values from reference-based reading. #342

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/ExtendedXmlSerializer/ContentModel/ConfiguredReader.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/ExtendedXmlSerializer/ContentModel/Format/SetContentCommand.cs

This file was deleted.

11 changes: 2 additions & 9 deletions src/ExtendedXmlSerializer/ContentModel/Properties/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@ class Property<T> : Identity, IProperty<T>
readonly ISerializer<T> _serializer;

public Property(IReader<T> reader, IWriter<T> writer, IIdentity identity)
: this(
new Serializer<T>(
identity is FrameworkIdentity
? new ConfiguredReader<T>(reader, SetContentCommand.Default)
: reader,
writer),
: this(new Serializer<T>(identity is FrameworkIdentity ? new TrackingReader<T>(reader) : reader, writer),
identity) {}

public Property(ISerializer<T> serializer, IIdentity identity) : base(identity.Name, identity.Identifier)
{
_serializer = serializer;
}
=> _serializer = serializer;

public T Get(IFormatReader parameter) => _serializer.Get(parameter);

Expand Down
18 changes: 18 additions & 0 deletions src/ExtendedXmlSerializer/ContentModel/TrackingReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using ExtendedXmlSerializer.ContentModel.Format;

namespace ExtendedXmlSerializer.ContentModel
{
sealed class TrackingReader<T> : IReader<T>
{
readonly IReader<T> _reader;

public TrackingReader(IReader<T> reader) => _reader = reader;

public T Get(IFormatReader parameter)
{
var result = _reader.Get(parameter);
parameter.Set();
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Reflection;
using ExtendedXmlSerializer.ContentModel;
using ExtendedXmlSerializer.ContentModel.Format;
using ExtendedXmlSerializer.ContentModel.Properties;
using ExtendedXmlSerializer.ContentModel.Reflection;
using JetBrains.Annotations;
using System;
using System.Reflection;

namespace ExtendedXmlSerializer.ExtensionModel.References
{
Expand Down Expand Up @@ -63,10 +63,12 @@ public Activator(IReader activator, IEntities entities, IReferenceMaps maps)

public object Get(IFormatReader parameter)
{
var declared = Identity(parameter);
var element = !string.IsNullOrEmpty(parameter.Identifier);

var declared = element ? Identity(parameter) : null;
var result = _activator.Get(parameter);

var identity = declared ?? (result != null ? Entity(parameter, result) : null);
var identity = declared ?? (element && result != null ? Entity(parameter, result) : null);

if (identity != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ sealed class ReferenceContents : IContents

[UsedImplicitly]
public ReferenceContents(IReferenceEncounters identifiers, IReferenceMaps maps, IEntities entities,
IContents option,
IClassification classification, IConverters converters)
IContents option, IClassification classification, IConverters converters)
: this(Specification, converters.IfAssigned(), identifiers, maps, entities, option, classification) {}

public ReferenceContents(ISpecification<TypeInfo> specification, ISpecification<TypeInfo> convertible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ public ReferenceReader(IReader reader, IReferenceMaps maps, IEntities entities,

ReferenceIdentity? GetReference(IFormatReader parameter)
{
var identity = ReferenceIdentity.Get(parameter);
if (identity.HasValue)
if (!string.IsNullOrEmpty(parameter.Identifier))
{
return new ReferenceIdentity(identity.Value);
}
var identity = ReferenceIdentity.Get(parameter);
if (identity.HasValue)
{
return new ReferenceIdentity(identity.Value);
}

var type = _classification.GetClassification(parameter, _definition);
var entity = _entities.Get(type)
?.Reference(parameter);
if (entity != null)
{
return new ReferenceIdentity(type, entity);
var type = _classification.GetClassification(parameter, _definition);
var entity = _entities.Get(type)?.Reference(parameter);
if (entity != null)
{
return new ReferenceIdentity(type, entity);
}
}

return null;
Expand All @@ -49,13 +51,14 @@ public override object Get(IFormatReader parameter)
var identity = GetReference(parameter);
if (identity != null)
{
var map = _maps.Get(parameter);
var reference = map.Get(identity.Value);
return reference;
var result = _maps.Get(parameter).Get(identity.Value);
return result;
}

var result = base.Get(parameter);
return result;
{
var result = base.Get(parameter);
return result;
}
}
}
}
Loading