From 26f84cf312b4ee9f735b3a3d2af6caf7b6c65c16 Mon Sep 17 00:00:00 2001 From: doxoh Date: Thu, 5 Sep 2024 17:21:48 +0200 Subject: [PATCH] fix(shared): fix cast --- api/AltV.Net.Shared/Utils/Utils.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/api/AltV.Net.Shared/Utils/Utils.cs b/api/AltV.Net.Shared/Utils/Utils.cs index 246a7096..e62007f2 100644 --- a/api/AltV.Net.Shared/Utils/Utils.cs +++ b/api/AltV.Net.Shared/Utils/Utils.cs @@ -76,7 +76,13 @@ public static T GetCastedMValue(MValueConst mValue) } else { - resultList.GetType().GetMethod("Add").Invoke(resultList, [Convert.ChangeType(item, type)]); + var val = item; + if (type != typeof(object)) + { + val = Convert.ChangeType(val, type); + } + + resultList.GetType().GetMethod("Add").Invoke(resultList, [val]); } } } @@ -125,8 +131,12 @@ public static T GetCastedMValue(MValueConst mValue) foreach (var kvp in sourceDictionary) { - object value = Convert.ChangeType(kvp.Value, valueType); - resultDictionary.GetType().GetMethod("Add").Invoke(resultDictionary, new object[] { kvp.Key, value }); + var val = kvp.Value; + if (valueType != typeof(object)) + { + val = Convert.ChangeType(val, valueType); + } + resultDictionary.GetType().GetMethod("Add").Invoke(resultDictionary, new object[] { kvp.Key, val }); } return resultDictionary;