elliebot/src/EllieBot/_common/Yml/UriConverter.cs
Toastie 547aa8b34d
Added common files
This took way too long
2024-06-18 23:44:07 +12:00

25 lines
No EOL
599 B
C#

#nullable disable
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
namespace EllieBot.Common.Yml;
public class UriConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
=> type == typeof(Uri);
public object ReadYaml(IParser parser, Type type)
{
var scalar = parser.Consume<Scalar>();
var result = new Uri(scalar.Value);
return result;
}
public void WriteYaml(IEmitter emitter, object value, Type type)
{
var uri = (Uri)value;
emitter.Emit(new Scalar(uri.ToString()));
}
}