Skip to content

Commit

Permalink
Make default serializer mutable again
Browse files Browse the repository at this point in the history
  • Loading branch information
Carnagion committed Jun 25, 2022
1 parent d081a76 commit 89172ff
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Serializer : ISerializer
/// <param name="referenceSources">An <see cref="IEnumerable{T}"/> of <see cref="XmlNode"/>s to use when deserializing <see cref="XmlNode"/>s that refer other <see cref="XmlNode"/>s through an ID.</param>
public Serializer(IEnumerable<XmlNode>? referenceSources = null)
{
this.specialized = new(19)
this.Specialized = new(19)
{
{typeof(string), Serializer.simple},
{typeof(char), Serializer.simple},
Expand All @@ -46,8 +46,8 @@ public Serializer(IEnumerable<XmlNode>? referenceSources = null)
{typeof(Vector3), Serializer.vector},
{typeof(Enum), new EnumSerializer()},
};
this.referenceSources = referenceSources?.ToArray();
this.referenceStorage = this.referenceSources is null ? null : new();
this.ReferenceSources = referenceSources?.ToHashSet();
this.referenceStorage = this.ReferenceSources is null ? null : new();
}

/// <summary>
Expand All @@ -57,9 +57,9 @@ public Serializer(IEnumerable<XmlNode>? referenceSources = null)
/// <param name="referenceSources">An <see cref="IEnumerable{T}"/> of <see cref="XmlNode"/>s to use when deserializing <see cref="XmlNode"/>s that refer other <see cref="XmlNode"/>s through an ID.</param>
public Serializer(OrderedDictionary<Type, ISerializer> specializedSerializers, IEnumerable<XmlNode>? referenceSources = null)
{
this.specialized = specializedSerializers;
this.referenceSources = referenceSources?.ToArray();
this.referenceStorage = this.referenceSources is null ? null : new();
this.Specialized = specializedSerializers;
this.ReferenceSources = referenceSources?.ToHashSet();
this.referenceStorage = this.ReferenceSources is null ? null : new();
}

private const BindingFlags instanceBindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
Expand All @@ -68,32 +68,22 @@ public Serializer(OrderedDictionary<Type, ISerializer> specializedSerializers, I

private static readonly VectorSerializer vector = new();

private readonly OrderedDictionary<Type, ISerializer> specialized;

private readonly XmlNode[]? referenceSources;

private readonly Dictionary<string, object?>? referenceStorage;

/// <summary>
/// Specialized <see cref="ISerializer"/>s for specific <see cref="Type"/>s. These serializers will be used by the <see cref="Serializer"/> when possible.
/// </summary>
public IReadOnlyDictionary<Type, ISerializer> Specialized
public OrderedDictionary<Type, ISerializer> Specialized
{
get
{
return this.specialized;
}
get;
}

/// <summary>
/// An <see cref="IEnumerable{T}"/> of <see cref="XmlNode"/>s that contain <see cref="XmlNode"/>s with IDs referenced by other <see cref="XmlNode"/>s.
/// A <see cref="HashSet{T}"/> of <see cref="XmlNode"/>s that contain <see cref="XmlNode"/>s with IDs referenced by other <see cref="XmlNode"/>s.
/// </summary>
public IEnumerable<XmlNode> ReferenceSources
public HashSet<XmlNode>? ReferenceSources
{
get
{
return this.referenceSources ?? Enumerable.Empty<XmlNode>();
}
get;
}

/// <summary>
Expand Down Expand Up @@ -333,7 +323,7 @@ private bool TryGetSpecialSerializerForType(Type type, [NotNullWhen(true)] out I
private bool TryDeserializeReferencedNode(XmlNode node, out object? instance)
{
instance = null;
if (this.referenceStorage is null)
if (this.referenceStorage is null || this.ReferenceSources is null)
{
return false;
}
Expand Down

0 comments on commit 89172ff

Please sign in to comment.