From 70060e9979ef409a886ef100d9de210203293cbc Mon Sep 17 00:00:00 2001 From: ale Date: Fri, 1 Sep 2023 16:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=20nullable=20GetValueOrDefau?= =?UTF-8?q?lt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VSProj/Src/Core/ReflectionMethodInvoker.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Source/VSProj/Src/Core/ReflectionMethodInvoker.cs b/Source/VSProj/Src/Core/ReflectionMethodInvoker.cs index 2de7441..b730435 100644 --- a/Source/VSProj/Src/Core/ReflectionMethodInvoker.cs +++ b/Source/VSProj/Src/Core/ReflectionMethodInvoker.cs @@ -34,6 +34,7 @@ internal class ReflectionMethodInvoker bool isNullableHasValue = false; bool isNullableValue = false; + bool isNullableGetValueOrDefault = false; public ReflectionMethodInvoker(MethodBase method) { @@ -75,6 +76,7 @@ public ReflectionMethodInvoker(MethodBase method) && method.DeclaringType.GetGenericTypeDefinition() == typeof(Nullable<>); isNullableHasValue = isNullableMethod && method.Name == "get_HasValue"; isNullableValue = isNullableMethod && method.Name == "get_Value"; + isNullableGetValueOrDefault = isNullableMethod && method.Name == "GetValueOrDefault"; } // #lizard forgives @@ -156,6 +158,20 @@ public unsafe void Invoke(VirtualMachine virtualMachine, ref Call call, bool isI { ret = instance; } + else if (isNullableGetValueOrDefault) + { + if(instance == null) + { + if(paramCount == 0) + ret = System.Activator.CreateInstance(returnType); + else + ret = args[0]; + } + else + { + ret = instance; + } + } else { if (method.IsStatic == false && instance == null)