Added protected constructors for serialization for all unsealed serializable classes

This commit is contained in:
ForeverZer0 2021-08-24 22:40:29 -04:00
parent b5005ffdcc
commit 87ddf70abf
16 changed files with 141 additions and 2 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -40,6 +41,15 @@ namespace SharpNBT
public ByteArrayTag([CanBeNull] string name, ReadOnlySpan<byte> values) : base(TagType.ByteArray, name, values)
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected ByteArrayTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString()

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -42,6 +43,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected ByteTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Byte({PrettyName}): {Value}";

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using JetBrains.Annotations;
@ -34,6 +35,15 @@ namespace SharpNBT
{
AddRange(values);
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected CompoundTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -18,6 +19,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected DoubleTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Double({PrettyName}): {Value}";

View File

@ -7,7 +7,7 @@ namespace SharpNBT
/// Represents the end of <see cref="CompoundTag"/>.
/// </summary>
[PublicAPI]
public class EndTag : Tag
public sealed class EndTag : Tag
{
/// <summary>
/// Creates a new instance of the <see cref="EndTag"/> class.

View File

@ -62,6 +62,11 @@ namespace SharpNBT
internalList.AddRange(values.ToArray());
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected EnumerableTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
var dummy = info.GetInt32("count");

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -17,6 +18,15 @@ namespace SharpNBT
public FloatTag([CanBeNull] string name, float value) : base(TagType.Float, name, value)
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected FloatTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Float({PrettyName}): {Value}";

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -45,6 +46,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected IntArrayTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString()
{

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -37,6 +38,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected IntTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Int({PrettyName}): {Value}";

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using JetBrains.Annotations;
@ -41,6 +42,15 @@ namespace SharpNBT
{
AddRange(children);
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected ListTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString()

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -26,6 +27,14 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected LongArrayTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="LongArrayTag"/> with the specified <paramref name="values"/>.

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -37,6 +38,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected LongTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Long({PrettyName}): {Value}";

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -37,6 +38,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected ShortTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_Short({PrettyName}): {Value}";

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
namespace SharpNBT
@ -18,6 +19,15 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected StringTag(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <inheritdoc cref="object.ToString"/>
public override string ToString() => $"TAG_String({PrettyName}): \"{Value}\"";

View File

@ -153,7 +153,12 @@ namespace SharpNBT
// ReSharper restore NonReadonlyMemberInGetHashCode
}
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected Tag(SerializationInfo info, StreamingContext context)
{
Type = (TagType) info.GetByte("type");
@ -187,6 +192,11 @@ namespace SharpNBT
/// </summary>
public T Value { get; set; }
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected Tag(SerializationInfo info, StreamingContext context) : base(info, context)
{
Value = (T)info.GetValue("value", typeof(T));

View File

@ -35,6 +35,11 @@ namespace SharpNBT
{
}
/// <summary>
/// Required constructor for ISerializable implementation.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> to describing this instance.</param>
/// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext" />) for this serialization.</param>
protected TagContainer(SerializationInfo info, StreamingContext context) : base(info, context)
{
RequiredType = (TagType?) info.GetValue("child_type", typeof(TagType?));