mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2025-12-12 01:23:31 +08:00
17 lines
451 B
C#
17 lines
451 B
C#
using System;
|
|
|
|
namespace AutoPilot.Commons;
|
|
|
|
internal static class EnumUtils
|
|
{
|
|
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct
|
|
{
|
|
if (value == null || !Enum.IsDefined(typeof(TEnum), value))
|
|
{
|
|
result = (TEnum)Enum.GetValues(typeof(TEnum)).GetValue(0);
|
|
return false;
|
|
}
|
|
result = (TEnum)Enum.Parse(typeof(TEnum), value);
|
|
return true;
|
|
}
|
|
} |