Files
TEngine/Assets/TEngine/Runtime/Utility/EnumHelper.cs
ALEXTANG a273e9d5f8 Entitas
Entitas
2023-07-17 15:28:27 +08:00

30 lines
505 B
C#

using System;
namespace TEngine
{
public static class EnumHelper
{
public static int EnumIndex<T>(int value)
{
int i = 0;
foreach (object v in Enum.GetValues(typeof (T)))
{
if ((int) v == value)
{
return i;
}
++i;
}
return -1;
}
public static T FromString<T>(string str)
{
if (!Enum.IsDefined(typeof(T), str))
{
return default(T);
}
return (T)Enum.Parse(typeof(T), str);
}
}
}