In my code, I declare one ArrayList within a ParentClass
public class ParentClass {
...
public ArrayList hybridElem;
...
and then using Reflection that runs off the ParentClass, I am able to successfully obtain FieldInfo for this ArrayList @ runtime.
Using that FieldInfo, I want to be able to add or read elements from the hybridElem.
I am able to obtain all relevant PropertyInfo of ArrayList such as .Item, .Count, .ToArray etc etc … and also obtain getters and setters for these properties.
Unfortunately, none of them are being successfully invoked because MethodInfo.Invoke expects Object reference to ArrayList
Any Solutions?
You can do it easily enough. However, as the comments rightfully stated, I suggest you to switch from
ArrayListto a generic collection.With:
Alternatively, to adapt it to your class which uses a field (assuming that said field is initialized somewhere):