Skip to content

Commit

Permalink
fix(shared): fix cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Sep 5, 2024
1 parent f743610 commit 26f84cf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions api/AltV.Net.Shared/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ public static T GetCastedMValue<T>(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]);
}
}
}
Expand Down Expand Up @@ -125,8 +131,12 @@ public static T GetCastedMValue<T>(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;
Expand Down

0 comments on commit 26f84cf

Please sign in to comment.