mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
44 lines
1.1 KiB
C#
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
|
|
}
|
|
}
|