Files
quro-animation-tools/AnimationEditor/MonoGame.Framework.Content.Pipeline/Serialization/Intermediate/NullableSerializer.cs
T
quinnvoker c585f312a5 Made AnimationEditor compatible with Dictionary SpriteMaps
Added MonoGame Pipeline's IntermediateSerializer and needed classes from the pipeline and  MonoGame.Framework.Utilities to make AnimationEditor capable of reading Dictionaries
2018-11-24 16:43:44 -08:00

35 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate
{
[ContentTypeSerializer]
class NullableSerializer<T> : ContentTypeSerializer<T?> where T : struct
{
private ContentTypeSerializer _serializer;
private ContentSerializerAttribute _format;
protected internal override void Initialize(IntermediateSerializer serializer)
{
_serializer = serializer.GetTypeSerializer(typeof(T));
_format = new ContentSerializerAttribute
{
FlattenContent = true
};
}
protected internal override T? Deserialize(IntermediateReader input, ContentSerializerAttribute format, T? existingInstance)
{
return input.ReadRawObject<T>(_format, _serializer);
}
protected internal override void Serialize(IntermediateWriter output, T? value, ContentSerializerAttribute format)
{
output.WriteRawObject<T>(value.Value, _format, _serializer);
}
}
}