Files
quro-animation-tools/AnimationEditor/MonoGame.Framework.Content.Pipeline/Serialization/Intermediate/NonGenericIListSerializer.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

56 lines
1.9 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.Collections;
namespace Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate
{
class NonGenericIListSerializer : ContentTypeSerializer
{
public NonGenericIListSerializer(Type targetType) :
base(targetType, targetType.Name)
{
}
public override bool CanDeserializeIntoExistingObject
{
get { return true; }
}
public override bool ObjectIsEmpty(object value)
{
return ((IList) value).Count == 0;
}
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance)
{
var result = (IList) (existingInstance ?? Activator.CreateInstance(TargetType));
// Create the item serializer attribute.
var itemFormat = new ContentSerializerAttribute();
itemFormat.ElementName = format.CollectionItemName;
// Read all the items.
while (input.MoveToElement(itemFormat.ElementName))
{
var value = input.ReadObject<object>(itemFormat);
result.Add(value);
}
return result;
}
protected internal override void Serialize(IntermediateWriter output, object value, ContentSerializerAttribute format)
{
// Create the item serializer attribute.
var itemFormat = new ContentSerializerAttribute();
itemFormat.ElementName = format.CollectionItemName;
// Read all the items.
foreach (var item in (IList) value)
output.WriteObject(item, itemFormat);
}
}
}