mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
EnumHelper
EnumHelper
This commit is contained in:
30
Assets/GameScripts/DotNet/Core/Helper/EnumHelper.cs
Normal file
30
Assets/GameScripts/DotNet/Core/Helper/EnumHelper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/GameScripts/DotNet/Core/Helper/EnumHelper.cs.meta
Normal file
3
Assets/GameScripts/DotNet/Core/Helper/EnumHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2638994be90d44a583fe978f8b92664d
|
||||
timeCreated: 1689578753
|
Reference in New Issue
Block a user