EnumHelper

EnumHelper
This commit is contained in:
ALEXTANG
2023-07-17 18:29:41 +08:00
parent ee2147e3d9
commit da35b4306b
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2638994be90d44a583fe978f8b92664d
timeCreated: 1689578753