using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using YamlDotNet.Core;
using YamlDotNet.RepresentationModel;
namespace Robust.Shared.Serialization
{
///
/// Helper for doing custom value representation in YAML.
///
/// The type for which this gives a custom representation.
public class YamlCustomFormatSerializer : YamlObjectSerializer.TypeSerializer
{
private readonly WithFormat _formatter;
public YamlCustomFormatSerializer(WithFormat formatter)
{
_formatter = formatter;
}
public override object NodeToType(Type _type, YamlNode node, YamlObjectSerializer serializer)
{
return _formatter.FromCustomFormat(serializer.NodeToType(_formatter.Format, node));
}
public override YamlNode TypeToNode(object obj, YamlObjectSerializer serializer)
{
var t = (T)obj;
return serializer.TypeToNode(_formatter.ToCustomFormat(t));
}
}
///
/// Convenience class for static access to custom formatters.
///
public static class WithFormat
{
public static WithFormat Flags()
{
return IoCManager.Resolve().FlagFormat();
}
public static WithFormat Constants()
{
return IoCManager.Resolve().ConstantFormat();
}
}
}