mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 17:08:00 +02:00
Moving corlib files out of "System" directory into root
This commit is contained in:
parent
4cd58262e4
commit
7dbfd15292
179 changed files with 3 additions and 0 deletions
41
BeefLibs/corlib/src/Enum.bf
Normal file
41
BeefLibs/corlib/src/Enum.bf
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Reflection;
|
||||
|
||||
namespace System
|
||||
{
|
||||
struct Enum
|
||||
{
|
||||
public static void EnumToString(Type type, String strBuffer, int64 iVal)
|
||||
{
|
||||
for (var field in type.GetFields())
|
||||
{
|
||||
if (field.mFieldData.mConstValue == iVal)
|
||||
{
|
||||
strBuffer.Append(field.Name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
((int32)iVal).ToString(strBuffer);
|
||||
}
|
||||
|
||||
public static Result<T> Parse<T>(StringView str, bool ignoreCase = false) where T : Enum
|
||||
{
|
||||
var typeInst = (TypeInstance)typeof(T);
|
||||
for (var field in typeInst.GetFields())
|
||||
{
|
||||
if (str.Equals(field.mFieldData.mName, ignoreCase))
|
||||
return .Ok(*((T*)(&field.mFieldData.mConstValue)));
|
||||
}
|
||||
|
||||
return .Err;
|
||||
}
|
||||
|
||||
/*public override void ToString(String strBuffer) mut
|
||||
{
|
||||
Type type = GetType();
|
||||
int32* iPtr = (int32*)((int)(&this) + (int)type.Size);
|
||||
EnumToString(type, strBuffer, *iPtr);
|
||||
//EnumToString(GetType(), )
|
||||
}*/
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue