Files
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

36 lines
1.2 KiB
C#

// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
namespace Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate
{
class EnumSerializer : ContentTypeSerializer
{
public EnumSerializer(Type targetType) :
base(targetType, targetType.Name)
{
}
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance)
{
var str = input.Xml.ReadString();
try
{
return Enum.Parse(TargetType, str, true);
}
catch (Exception ex)
{
throw input.NewInvalidContentException(ex, "Invalid enum value '{0}' for type '{1}'", str, TargetType.Name);
}
}
protected internal override void Serialize(IntermediateWriter output, object value, ContentSerializerAttribute format)
{
Debug.Assert(value.GetType() == TargetType, "Got invalid value type!");
output.Xml.WriteString(value.ToString());
}
}
}