This question already has an answer here:
Consider following code:
var arrayOfBaseClass = (from instance in results select instance.GetComponent(arrayOfDerivedClass.Field.FieldType.GetElementType())).ToArray();
// Missing Step here
arrayOfDerivedClass.Field.SetValue(o, arrayOfBaseClass);
I get an array of some base class results (Component in this case) and have a field of a array of a type which dervies from component. Is there a way how I can use reflection / some magic to to a cast here?
SetValue throws right now ArgumentException: Object type UnityEngine.Component[] cannot be converted to target type: VEL.Input.ActionSignalReceiver[]
I do know the type by the reflected info in arrayOfDerivedClass, but it is any arbitrary type derived from Component.
Aucun commentaire:
Enregistrer un commentaire