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
D. Moonfire 9e93eb6ce6 refactor!: fixed missed namespaces
- reformatted code and cleaned up references
2023-01-14 18:19:42 -06:00

42 lines
994 B
C#

using System;
using MfGames.Gallium;
using MfGames.Nitride.Contents;
using YamlDotNet.Serialization;
namespace MfGames.Nitride.Yaml;
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();
return text != null
? deserializer.Deserialize<TType>(text)
: default;
}
}