Files
SabreTools.Serialization/SabreTools.Metadata/Converters.cs
2026-03-26 22:51:14 -04:00

44 lines
1.1 KiB
C#

namespace SabreTools.Metadata
{
public static class Converters
{
#region String to Enum
/// <summary>
/// Get bool? value from input string
/// </summary>
/// <param name="yesno">String to get value from</param>
/// <returns>bool? corresponding to the string</returns>
public static bool? AsYesNo(this string? yesno)
{
return yesno?.ToLowerInvariant() switch
{
"yes" or "true" => true,
"no" or "false" => false,
_ => null,
};
}
#endregion
#region Enum to String
/// <summary>
/// Get string value from input bool?
/// </summary>
/// <param name="yesno">bool? to get value from</param>
/// <returns>String corresponding to the bool?</returns>
public static string? FromYesNo(this bool? yesno)
{
return yesno switch
{
true => "yes",
false => "no",
_ => null,
};
}
#endregion
}
}