mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Added GetCurEnum
This commit is contained in:
parent
bb59aa3162
commit
79acc766fd
1 changed files with 17 additions and 0 deletions
|
@ -589,6 +589,23 @@ namespace Beefy.utils
|
|||
return;
|
||||
}
|
||||
|
||||
public T GetCurEnum<T>(T theDefault = default) where T : Enum
|
||||
{
|
||||
Object obj = GetCurrent();
|
||||
|
||||
Result<T> result;
|
||||
if (let str = obj as String)
|
||||
result = Enum.Parse<T>(str);
|
||||
else if (obj is StringView)
|
||||
result = Enum.Parse<T>((StringView)obj);
|
||||
else
|
||||
return theDefault;
|
||||
|
||||
if (result case .Ok(var val))
|
||||
return val;
|
||||
return theDefault;
|
||||
}
|
||||
|
||||
public int32 GetCurInt(int32 theDefault = 0)
|
||||
{
|
||||
Object aVal = GetCurrent();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue