From 79acc766fd9f561e10d3fbab8c28bea4282fb1f8 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 2 Apr 2020 08:57:15 -0700 Subject: [PATCH] Added GetCurEnum --- BeefLibs/Beefy2D/src/utils/StructuredData.bf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/BeefLibs/Beefy2D/src/utils/StructuredData.bf b/BeefLibs/Beefy2D/src/utils/StructuredData.bf index 6650424f..7dc6fd3a 100644 --- a/BeefLibs/Beefy2D/src/utils/StructuredData.bf +++ b/BeefLibs/Beefy2D/src/utils/StructuredData.bf @@ -589,6 +589,23 @@ namespace Beefy.utils return; } + public T GetCurEnum(T theDefault = default) where T : Enum + { + Object obj = GetCurrent(); + + Result result; + if (let str = obj as String) + result = Enum.Parse(str); + else if (obj is StringView) + result = Enum.Parse((StringView)obj); + else + return theDefault; + + if (result case .Ok(var val)) + return val; + return theDefault; + } + public int32 GetCurInt(int32 theDefault = 0) { Object aVal = GetCurrent();