Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array copy problem #28

Open
qiyuedunk opened this issue Jan 11, 2020 · 0 comments
Open

array copy problem #28

qiyuedunk opened this issue Jan 11, 2020 · 0 comments

Comments

@qiyuedunk
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant