I have a FieldInfo, and I know it's an array so I use its value to declare an Array instance, and also get the type of the array elements:
void Test(object baseInstance, FieldInfo baseInstanceField) {
Array a = (Array)baseInstanceField.GetValue(baseInstance);
Type elementType = TypeSystem.GetElementType(baseInstance.GetType());
}
Now I want to initialize a new array of type elementType with a specific length using reflection. How do I do this? I later will have to access the elements of this new array.
elementType[] newArray = new elementType[34]; //doesn't work
The type or namespace name `elementType' could not be found. Are you missing a using directive or an assembly reference?