This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride.Yaml/NitrideYamlEntityExtensions.cs

42 lines
994 B
C#
Raw Normal View History

2022-07-18 22:13:33 +00:00
using System;
2022-09-06 05:53:22 +00:00
using MfGames.Gallium;
using MfGames.Nitride.Contents;
2022-07-18 22:13:33 +00:00
using YamlDotNet.Serialization;
2022-09-06 05:53:22 +00:00
namespace MfGames.Nitride.Yaml;
2022-07-18 22:13:33 +00:00
public static class NitrideYamlEntityExtensions
{
/// <summary>
/// Parses the entity text as a YAML file and returns the results.
/// </summary>
public static TType? GetYaml<TType>(
this Entity entity,
Action<DeserializerBuilder>? configure = null)
{
DeserializerBuilder builder = new();
configure?.Invoke(builder);
IDeserializer deserializer = builder.Build();
return entity.GetYaml<TType>(deserializer);
}
/// <summary>
/// Parses the entity text as a YAML file and returns the results.
/// </summary>
public static TType? GetYaml<TType>(
this Entity entity,
IDeserializer deserializer)
{
string? text = entity.GetText();
2022-07-18 22:13:33 +00:00
return text != null
? deserializer.Deserialize<TType>(text)
: default;
2022-07-18 22:13:33 +00:00
}
}