Apparently making an array through reflection like this:
typeof(object).MakeArrayType()
Makes an array that doesn’t function quite the same as doing this:
new object[0]
Long story short, I’m reading in arrays of all different data types from a file and I realized that the array created by MakeArrayType could not be casted to be an IEnumerable object. However, a normally made array could.
Here’s an example of this in action:
object byReflection = (typeof(int)).MakeArrayType();
int[] normal = new int[0];
Debug.Log(byReflection);
Debug.Log(normal);
IEnumerable convertTo;
try
{
convertTo = (IEnumerable)byReflection;
Debug.Log(convertTo);
}
catch(Exception e)
{
Debug.Log(e.Message);
}
` try { convertTo = (IEnumerable)normal; Debug.Log(convertTo); } catch(Exception e) { Debug.Log(e.Message); }`
Any idea on why this is happening and/or how I can make an array given I have the Type object for it (or its element type)?