I have an ArrayList of objects that are of a certain type, and I need to convert this ArrayList in to a types list. Here is my code
Type objType = Type.GetType(myTypeName);
ArrayList myArrayList = new ArrayList();
object myObj0 = Activator.CreateInstance(type);
object myObj1 = Activator.CreateInstance(type);
object myObj2 = Activator.CreateInstance(type);
myArrayList.Add(myObj0);
myArrayList.Add(myObj1);
myArrayList.Add(myObj2);
Array typedArray = myArrayList.ToArray(objType); // this is typed
object returnValue = typedArray.ToList(); // this is fake, but this is what I am looking for
There is no ToList() available for an Array, this is the behaviour I am looking for
object returnValue = typedArray.ToList();
So basically I have the type name as a string, I can create a Type from the name, and create a collection containing several objects typed, but how do I convert that to a List? I am hydrating a property and when I do a SetValue my property type needs to match.
Thank you very much.