Open
Description
hi, have you ever try to copy a List object? when I try it on Unity's c# script, it failed. When I debug the code, I found that the array's copy pass the case when the element type is Primitive.
var arrayType = typeToReflect.GetElementType();
if (IsPrimitive(arrayType) == false)
{
Array clonedArray = (Array)cloneObject;
clonedArray.ForEach((array, indices) => array.SetValue(InternalCopy(clonedArray.GetValue(indices), visited), indices));
}
But this cause the primitive element array would not get the memory allocated, after I add code
else
{
Array oArr = (Array)originalObject;
Array clonedArray = Array.CreateInstance(arrayType, oArr.Length);
Array.Copy(oArr, clonedArray, oArr.Length);
cloneObject = clonedArray;
}
it fixed.
Metadata
Assignees
Labels
No labels
Activity