From c58f3271365d1171aafcbdbbfddbd0bf9ce1a9ce Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 22 Feb 2024 06:52:11 -0500 Subject: [PATCH] Variant TryGet --- BeefLibs/corlib/src/Variant.bf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BeefLibs/corlib/src/Variant.bf b/BeefLibs/corlib/src/Variant.bf index 3289f1f9..624e90a1 100644 --- a/BeefLibs/corlib/src/Variant.bf +++ b/BeefLibs/corlib/src/Variant.bf @@ -65,6 +65,8 @@ namespace System } if (mStructType <= 1) { + if (mData == 0) + return null; return Internal.UnsafeCastToObject((void*)mData).GetType(); } return (Type)Internal.UnsafeCastToObject((void*)(mStructType & ~3)); @@ -343,6 +345,15 @@ namespace System return *(T*)(void*)mData; } + public bool TryGet(out T value) + { + value = default; + if (VariantType != typeof(T)) + return false; + value = Get(); + return true; + } + public Result GetBoxed() { if (IsObject)